问题描述
input [type =checkbox]:checked + span 在IE中不起作用。实际上,当检查元素完成时,开发人员工具中甚至没有看到样式规则。
input[type="checkbox"]:checked + span does not work in IE. Actually the style rule is not even seen in the developers tool, when inspect element is done.
<label> <input type="checkbox" name="Hello" id="Hello"/> <span>Hello</span> </label>
CSS:
CSS:
input[type="checkbox"]:checked + span { font-weight:bold; }
当复选框被选中时,我试图让span变粗体。这是在Chrome中工作,但不是在IE8中。另外,Ø验证为什么它不工作,我试图检查元素,我在那里找到了这个样式规则。希望这是明确的。
When the checkbox is checked, I am trying to make the span bold. This is working in Chrome, but not in IE8. Also, o verify why its not working, I was trying to inspect the element, I did find this style rule there. Hope this is clear.
有没有其他的解决方案呢?
Is there any other solution to this?
推荐答案
因为你只能选择使用javascript,所以你可以这样做(如果你想使用jquery):
since you're only option is to do it with javascript,you can do something like this(if you want to use jquery):
function checkboxIscheckedHandler(el) { var _this = $(el); if (_this.checked) _this.next('span').css("font-weight", "bold"); else _this.next('span').css("font-weight", "normal"); }
,您只需将此函数添加到每个复选框的 onchange 这样的属性
and you just add this function to every checkbox's onchange property like this
<input type="checkbox" onchange="checkboxIscheckedHandler(this)" name="Hello" id="Hello"/>
这篇关于输入[类型="复选框"]:选中+ span在IE8中无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!