jQuery 查看是否选中了任何复选框 [英] jQuery see if any or no checkboxes are selected

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

问题描述

我知道如何查看单个复选框是否被选中.

I know how to see if an individual checkbox is selected or not.

但是我遇到了以下问题 - 给定一个表单 ID,我需要查看是否选择了任何复选框(即 1 个或多个),我需要查看是否没有 被选中.基本上我需要两个独立的函数来回答这两个问题.帮助将不胜感激.谢谢!

But Im having trouble with the following - given a form id I need to see if any of the checkboxes are selected (i.e 1 or more), and I need to see if none are selected. Basically I need two separate functions that answer these two questions. Help would be appreciated. Thanks!

实际上,我只需要一个函数来告诉我是否选择了 none.知道这一点将回答另一个问题.

Actually, I would just need a function to tell me if none are selected. Knowing this would answer the other question.

推荐答案

你可以这样使用

if ($("#formID input:checkbox:checked").length > 0)
{
    // any one is checked
}
else
{
   // none is checked
}

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

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