我尝试了所有的polyfills。除了 ie9.js,它们都不起作用。不幸的是,ie9.js让我的页面加载速度就像一群蜗牛穿过花生酱一样慢。经过近 2(!) 天的诅咒,我终于得到了 IE8 单选按钮,它与一点点 jQuery 和 CSS 一起工作。
第一个问题是向未检查/检查的输入添加和删除一个类。其次是强制 IE8 在选中另一个单选按钮后重新呈现未选中的输入。我认为这种方法也适用于复选框。
jQuery:
// maybe you need this next small line, I didn't
// $('input:checked').addClass("selected");
$('input').change(function () { // click() worked too but change is safer
$(this).addClass("selected");
$('input:not(:checked)').removeClass("selected");
// adding a class to a wrapping element
// and then remove it to force IE8 to rerender
var testClass = "testClass";
$(this).parent().parent().addClass(testClass).removeClass(testClass);
});
和CSS:
input[type="radio"] {
// display: none; won't work
// so replace the actual button offscreen
// or cover it with following label
}
input[type="radio"] + label {
background-color: red; // or background-image
}
input[type="radio"].selected + label {
background-color: green; // or background-image
}
input[type="radio"] + label,
input[type="radio"].selected + label {
position: relative;
top: 150px;
left: 300px;
height: 48px;
width: 48px;
display:inline-block;
padding: 0;
text-indent: -9999px;
cursor: pointer;
}