检查所选复选框的数量 [英] Checking Number of Selected Checkboxes
本文介绍了检查所选复选框的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jQuery中看到了 is 函数,例如,如果有任何复选框被选中.
I saw the is function in jQuery, and it returns me, for example, if any of the checkboxes are selected.
我需要检查用户选择了多少个复选框,因为我的应用需要选择其中两个"之类的东西.有快速的方法吗?
I need to do a check for how many checkboxes had been selected by the user, because my app requires something like "select two of these". Is there a quick way to do it?
此外,根据检查,我如何捕捉用户单击提交"然后能够决定是否让表单发送?
Also, how can I catch when the user clicks the "submit" and then be able to decide whether to let the form send or not, according to checks?
推荐答案
要获取选中的复选框数量并绑定到提交"按钮:
To get the amount of checkboxes checked and bind to the submit button:
$("#yourButton").click(function(e){
var n = $("input:checked").length; //Checkbox count, may need refined
if(n<2) //using n from above.
{
e.preventDefault();
}
});
工作示例: http://jsfiddle.net/ZtTG2/
这篇关于检查所选复选框的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文