检查jQuery是否选中了复选框

检查jQuery是否选中了复选框,第1张

检查jQuery是否选中了复选框

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

<input type="checkbox" name="chk[]" id="chk[]" value="Apples" /><input type="checkbox" name="chk[]" id="chk[]" value="Bananas" />

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

<fieldset id="checkArray">    <input type="checkbox" name="chk[]" value="Apples" />    <input type="checkbox" name="chk[]" value="Bananas" /></fieldset>

现在是jQuery:

var atLeastoneIsChecked = $('#checkArray:checkbox:checked').length > 0;//there should be no space between identifier and selector// or, without the container:var atLeastoneIsChecked = $('input[name="chk[]"]:checked').length > 0;


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5440017.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存