我有一组 checkbox_item
类的复选框。我需要循环遍历所有未选中的复选框及其分割的 #ID
值的第二部分,
即 $('.checkbox_item').prop('id').split('_')[1]
不应等于零
<input class="checkbox_item" id="414_0.5" type="checkbox">test
<input class="checkbox_item" id="415_1" type="checkbox">test1
<input class="checkbox_item" id="416_0.5" type="checkbox">test2
<input class="checkbox_item" id="417_0" type="checkbox">test3
我的jquery函数如下:
$('.checkbox_item').not(':checked').each(function(index,elem){
/here I dont need checkboxes whose splitted #ID [1] not equals to zero
});
我用谷歌搜索了一下,找不到任何积极的东西。提前致谢
最佳答案
不确定我是否正确理解了您的问题,因为您几乎已经有了答案。尽管如此,希望以下内容有所帮助:
$('.checkbox_item').not(':checked').each(function(index,elem){
var id = $(this).prop('id').split('_')[1];
// Use `!=` instead of `!==` to allow type coercion to occur, in order to compare with `0`
if (id != 0) {
console.log(id);
// Manipulate current DOM element using jQuery `$(this)`
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="checkbox_item" id="414_0.5" type="checkbox">test
<input class="checkbox_item" id="415_1" type="checkbox">test1
<input class="checkbox_item" id="416_0.5" type="checkbox">test2
<input class="checkbox_item" id="417_0" type="checkbox">test3
关于javascript - jquery中循环复选框不等于0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44128428/