jQuery的事件。目标不工作在firefox和IE?

时间:2021-07-07 20:36:27

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:

我正在制作一个图像滑块,使用jQuery加载用户单击的图像。我在Chrome上运行得很好,但是当我在火狐和IE上尝试的时候,它根本没有加载图像。这是我的代码:

    $("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? :)

当我在firefox或IE中运行时,它根本不会加载图像。什么好主意吗?:)

4 个解决方案

#1


9  

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.

否则它将使用window.event。

#2


1  

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

尝试使用$(this).attr('src')而不是event.target.src

#3


1  

Try this :

试试这个:

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

#4


0  

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

$(" img.clickable”)。点击(函数(e){ $(" # image_slider ").animate({不透明度:1.0,左:200 },“慢”);$(" # image_container”).attr(" src ",$(e。target).attr(src));ihidden = false;});

This should work just fine

这应该没问题

#1


9  

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.

否则它将使用window.event。

#2


1  

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

尝试使用$(this).attr('src')而不是event.target.src

#3


1  

Try this :

试试这个:

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

#4


0  

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

$(" img.clickable”)。点击(函数(e){ $(" # image_slider ").animate({不透明度:1.0,左:200 },“慢”);$(" # image_container”).attr(" src ",$(e。target).attr(src));ihidden = false;});

This should work just fine

这应该没问题