如何检查是否取消选中所有复选框 [英] How to check if all checkboxes are unchecked

查看:105
本文介绍了如何检查是否取消选中所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个函数来检查是否取消选中所有复选框。我有一个类似的文本框功能。由于我以前没有使用过复选框,我不知道除了将输入[type = text] 更改为输入之外如何调整它[ type = checkbox]

I am trying to make a function to check if all checkboxes are unchecked. I have a similar function for text boxes. As I have not worked with checkboxes much before, I'm not sure how to adapt it except for changing input[type=text] to input[type=checkbox].

任何人都可以帮帮我吗?谢谢。

Can anyone help me out? Thanks.

var textinputs = document.querySelectorAll('input[type=text]'); 
var empty = [].filter.call( textinputs, function( el ) {
     return !el.value
});

    if (textinputs.length == empty.length) {
        alert("None filled");
        return false;
}


推荐答案

以下应该做的伎俩:

var textinputs = document.querySelectorAll('input[type=checkbox]'); 
var empty = [].filter.call( textinputs, function( el ) {
   return !el.checked
});

if (textinputs.length == empty.length) {
    alert("None filled");
    return false;
}

这篇关于如何检查是否取消选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆