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. 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({opa开发者_如何学JAVAcity: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? :)
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
精彩评论