jQuery swapped image not loading

前端 未结 2 624
感情败类
感情败类 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 16:58

    This should work in most browsers. Have you used Firebug or something like that to see if the browser is attempting to download the new image? Maybe there is something wrong with the URL (wrong location, not URL encoded, etc)...

    0 讨论(0)
  • 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  + '); ')
    
        });
    
    0 讨论(0)
提交回复
热议问题