jQuery swapped image not loading

前端 未结 2 637
感情败类
感情败类 2021-01-28 16:25

I\'m trying to get an image to swap on the click event of a div class using jQuery .attr from the original image source location of \"Images/origImage\" to a new image source lo

2条回答
  •  太阳男子
    2021-01-28 17:02

    I've implemented something similar using the background style, I wonder if this would help you out. I split out the img variable explicitly:

      $("div.xxx").click(function(){
    
        var img = 'path/toNew.jpg';    
        $('.changesrc').attr('style', 'background: url(' + img  + '); ')
    
        });
    

提交回复
热议问题