您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

检查是否已使用jQuery选中复选框

检查是否已使用jQuery选中复选框

ID在您的文档中必须是唯一的,这意味着您不应该这样做:

<input type="check@R_69_2419@" name="chk[]" id="chk[]" value="Apples" />
<input type="check@R_69_2419@" name="chk[]" id="chk[]" value="Bananas" />

而是删除ID,然后按名称或包含元素选择它们:

<fieldset id="checkArray">
    <input type="check@R_69_2419@" name="chk[]" value="Apples" />

    <input type="check@R_69_2419@" name="chk[]" value="Bananas" />
</fieldset>

现在是jQuery:

var atLeastOneIsChecked = $('#checkArray:check@R_69_2419@:checked').length > 0;
//there should be no space between identifier and selector

// or, without the container:

var atLeastOneIsChecked = $('input[name="chk[]"]:checked').length > 0;
$('#' + id).is(":checked")

如果选中此复选框,则可以得到。

对于具有相同名称的复选框数组,您可以通过以下方式获取已选中复选框的列表:

var $@R_69_2419@es = $('input[name=thename]:checked');

然后遍历它们并查看已检查的内容,您可以执行以下操作:

$@R_69_2419@es.each(function(){
    // Do stuff here with this
});

要查找已检查的数量,您可以执行以下操作:

$@R_69_2419@es.length;
JS 2022/1/1 18:18:11 有355人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶