所以,我有这个包含我选中的复选框的下一个变量:
var checked = $('input[name="article[]"]:checked');
但是我怎么知道是否有 1 个已选中、2 个或什至没有?因为console.log(checked.length)
总是返回 1。
所以,我有这个包含我选中的复选框的下一个变量:
var checked = $('input[name="article[]"]:checked');
但是我怎么知道是否有 1 个已选中、2 个或什至没有?因为console.log(checked.length)
总是返回 1。
I know it's a stupid mistake but for everybody to know, the problem was that I was doing this:
if(checked.length = 1) {
instead of this
if(checked.length == 1) {
btw, I don't know why the "hate" on the other answers (for those who down voted), the answers given... work (I've tested 2 of them)
谁点击了代码悖论的答案?右选择器,只需要长度
<input type="checkbox" name="article" value="1" />
<input type="checkbox" name="article" value="2" />
<input type="checkbox" name="article" value="3" />
<button>go</button>
js
$(document).ready(function(){
$('button').click(function(){
alert($('input[name^="article"]:checked').length)
})
});