繁体   English   中英

jQuery的图像选择器无法在IE7

[英]jquery image selector not working in IE7

所以我有一些类似这样的html:

<div id="avatar_choices">
    <label for="id_choice_0">
        <input id="id_choice_0" type="radio" name="choice" value="7" />
        <img src="someimage.jpg" />
    </label>
    <label for="id_choice_1">
        <input id="id_choice_1" type="radio" name="choice" value="8" />
        <img src="someimage2.jpg" />
    </label>
</div>

和一些脚本:

$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
    $('#avatar_choices img').css('border', '2px solid #efefef');
    $(this).css('border', '2px solid #39c');
    $(this).siblings('input').attr('checked', 'checked');
});

目的是允许用户单击图像选项,使选中的一个高光具有边框颜色。

这在FF中效果很好。 出于某种原因,在IE中,一旦我单击图像,单击另一个图像,然后尝试单击第一个图像,边框就不会改变(尽管它确实被选中了)。

编辑:我的解决方案最终偶然发生了一半。 由于redsquare的回答,我将代码更改为此:

$('#avatar_choices input').hide();
$('#avatar_choices img').click(function(){
    $('#avatar_choices img').removeClass('selected');
    $(this).addClass('selected');
    $(this).siblings('input').attr('checked', 'checked');
});

哪里:

#avatar_choices img.selected{border:2px solid #39c;}

去搞清楚。

在这种情况下,最好使用addClass和removeClass。 易于维护。 您可以粘贴完整的html吗,以便我可以看到您的doctype等

暂无
暂无

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

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