最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery event.target not working in firefox and IE? - Stack Overflow

programmeradmin3浏览0评论

I'm working on making an image slider that loads the image the user clicks on using jQuery. I have it working great in Chrome but when I tried it in firefox and IE it's not loading the image at all. Here's my code:

    $("img.clickable").click( function() {
    $("#image_slider").animate({opacity:1.0,left:200},"slow");
    $("#image_container").attr("src",event.target.src);
    ihidden = false;
});

When I try running this in firefox or IE it just doesn't load the image at all. Any ideas? :)

I'm working on making an image slider that loads the image the user clicks on using jQuery. I have it working great in Chrome but when I tried it in firefox and IE it's not loading the image at all. Here's my code:

    $("img.clickable").click( function() {
    $("#image_slider").animate({opacity:1.0,left:200},"slow");
    $("#image_container").attr("src",event.target.src);
    ihidden = false;
});

When I try running this in firefox or IE it just doesn't load the image at all. Any ideas? :)

Share Improve this question asked May 1, 2011 at 4:31 CaffeinatedCMCaffeinatedCM 7641 gold badge11 silver badges24 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 10

You need to define the event in the arguments.

$("img.clickable").click( function(event) {
    $("#image_slider").animate({opacity:1.0,left:200},"slow");
    $("#image_container").attr("src",event.target.src);
    ihidden = false;
});

Otherwise it is going to use window.event.

try using $(this).attr('src') instead of event.target.src

Try this :

target = (window.event) ? window.event.srcElement /* for IE */ : event.target

$("img.clickable").click( function(e) { $("#image_slider").animate({opacity:1.0,left:200},"slow"); $("#image_container").attr("src",$(e.target).attr('src')); ihidden = false; });

This should work just fine

发布评论

评论列表(0)

  1. 暂无评论