简体   繁体   English

jQuery event.target 在 firefox 和 IE 中不起作用?

[英]jQuery event.target not working in firefox and IE?

I'm working on making an image slider that loads the image the user clicks on using jQuery.我正在制作一个图像 slider 加载用户点击使用 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.我让它在 Chrome 中运行良好,但是当我在 firefox 和 IE 中尝试它时,它根本没有加载图像。 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.当我尝试在 firefox 或 IE 中运行它时,它根本不会加载图像。 Any ideas?有任何想法吗? :) :)

You need to define the event in the arguments.您需要在 arguments 中定义event

$("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 .否则它将使用window.event

try using $(this).attr('src') instead of event.target.src尝试使用$(this).attr('src')而不是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这应该工作得很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM