gpt4 book ai didi

jQuery :not selector not working in ie

转载 作者:行者123 更新时间:2023-12-01 01:39:34 26 4
gpt4 key购买 nike

我有以下 html 代码:

<ul>
<li class="O">
<label for="radio1">Radio 1:</label>
<input type="radio" name="radio1" value="Yes" checked>Yes</input>
<input type="radio" name="radio1" value="No">No</input>
</li>
<li class="O">
<label for="checkbox1">Checkbox 1:</label>
<input type="checkbox" name="checkbox1" id="checkbox1" value="check"></input>
</li>
</ul>

使用 jQuery,我想对每个未选中的复选框或具有 O 类的 li 元素内具有空值的元素执行一些操作。这是我的方法:

$('li').each(function(){
if ($(this).hasClass('O')){
$(this).children(':not(label,input:radio)').each(function(){
if ( $(this).val() == "" || $(this).is(':checkbox:not(:checked)') ) {
//do something
}
});
}

此代码适用于 FF、Opera、Chrome 和 Safari,但不适用于 IE6-IE7。

对于这两个 IE,使用 $(this).children(':not(label,input:radio)').length 获取 li 的长度会返回 2 ,其他浏览器会返回 0 和 1。

此外,获取第一个 li 中非标签的子元素数量 ($(this).children(':not(label)').length) 返回 4,而获取子元素数量 ($(this) .children().length) 返回 2。这对我来说根本没有意义。

我是否错了,或者我使用的选择器中是否存在与 IE 不完全兼容的内容?

提前致谢。

最佳答案

如果我理解正确的话,你会尝试操作未选中且位于 O 类 li 内的复选框。我没有IE来测试,但我简化了一点。你能尝试一下吗?

$('li.O').each(function(){
$(this).children(':checkbox:not(:checked)').each(function(){
//stuff
});
});

更新:根据评论,您可以尝试以下操作:

$('li.O').each(function(){
$(this).children(':checkbox:not(:checked), :not(label,input:radio)[value=]').each(function(){
//stuff
});

});

关于jQuery :not selector not working in ie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2763691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com