我们有一个问题会导致 IE 8 和 IE 9 出现问题。单击标签时,应选中单选框。这在所有浏览器中都很好,除了 IE 8/9,它不检查单选按钮
<label for="so100">
<img alt="" src="images/type6img.jpg" class="anitem1pic">
<input type=radio value=1 name="site" id="so100" />
<span class="anitem1">Stag</span>
</label>
Known IE "bug"包裹的图像不会触发 radio
在your example ,文字有效,图像无效:
这里有建议的副本
Clickable label not working in IE 8
这是基于 Using images as labels in internet explorer 的经过测试的解决方法.文章中的解决方案破坏了 Chrome。我在条件注释中的包装可以防止脚本破坏点击时触发的浏览器。您可以更改 if IE
至 if IE8
如果 IE9 和 10 像 Chrome 一样工作
Live Demo
<!--[if IE]>
<script type="text/javascript">
$(function() {
$("label img").on("click", function() {
$("#" + $(this).parents("label").attr("for")).click();
});
});
</script>
<![endif]-->
My idea to have two labels也不起作用,因为这是 IE 提示的图像。
<label for="so100">
<img alt="" src="http://lorempixel.com/output/abstract-q-c-50-50-8.jpg" class="anitem1pic">
</label>
<input type=radio value=1 name="site" id="so100" />
<label for="so100">
<span class="anitem1">Stag</span>
</label>
但是使用背景图片会起作用