简体   繁体   中英

Jquery on click function is not working for img in IE 8

I've got a bunch of radio buttons and images. I'm trying to make the images clickable because I would like to use the images in place of the radio buttons. I'm using CSS to hide the radio buttons and in Firefox this script works great, but it doesn't work at all in IE (nothing happens when you click on the image). Any ideas of what I'm doing wrong?

$(document).ready(function() {
    $('img').click(function() {
        $(this).next().click();
    });
});​

I'm using jquery 1.6.1.

I do not want to change the image after it is clicked, I only want to be able to click the image and use it in place of the radio box. I am able to click the image in Firefox, but not in IE.

I've tried changing the script to this and it works in IE without any problems:

$(document).ready(function() {
$('img').click(function(){
alert("Show me");
});
});

http://jsfiddle.net/uJ9tK/1/

The code you have shown us is correct. Whether you hide the radio buttons or not, they are being clicked. Whatever you do when the radio buttons are clicked is the part that is broken. I tested this in IE7, 8, 9 and compatibility mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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