美文网首页
判断checkbox是否被选中

判断checkbox是否被选中

作者: 程序员的自我修养 | 来源:发表于2020-05-29 09:03 被阅读0次

 如果判断checkbox是否有选中的(即选中个数不为0)

if($("[name='chk']:checkbox:checked").length > 0){...........................................}

如果判断checkbox是否全部被选中

if($("[name='chk']:checkbox:checked").length==$("[name='chk']:checkbox").length){...........................................}

如果通过onclick判断当前点击的是否被选中:

input可以这么写:<input type="checkbox" name="chk" onclick= "ban(this)" value="北京"/>

function ban(obj){

    if(obj.checked){

          ..........

    }

    //如果要用到"北京" 可以调用obj.value

}

相关文章

网友评论

      本文标题:判断checkbox是否被选中

      本文链接:https://www.haomeiwen.com/subject/rzquohtx.html