【发布时间】:2013-11-20 10:29:20
【问题描述】:
我有大约 100 门课程,带有 course-chkbox 类的复选框,我正在使用以下代码:
//Make sure user has checked at least one course
if ($('.course-chkbox:checked').length === 0) {
alert('You have to have at least one course selected');
return false;
}
基于我使用的是最新版本的 jQuery,这是正确的吗?
基于一些谷歌搜索,有很多关于如何解决同一问题的建议......
1. Usage of is("checked")
2. Usage of prop()
3. Looping through the elements involved and check each element if it's checked
最好的解决方案是什么?为什么?
【问题讨论】:
-
我认为您当前的解决方案是最好的。
标签: javascript jquery loops checkbox prop