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

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

问题描述

我知道如何选择是否选中了一个单独的复选框。

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

但我遇到以下问题 - 给定一个表单ID我需要看看是否<选择em>任何复选框(即1个或更多),我需要查看是否选择了 none 。基本上我需要两个独立的功能来回答这两个问题。帮助将不胜感激。谢谢!

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天全站免登陆