Jquery“选择所有”复选框 [英] Jquery "select all" checkbox
本文介绍了Jquery“选择所有”复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图选中页面上的所有复选框,点击'select all'复选框,我正在使用jquery,如下所示:
http://jsfiddle.net/priyam/K9P8A/
选择和取消选中所有复选框的代码是:
function selectAll(){
$('。selectedId')。attr('checked',isChecked('selectall'));
}
函数isChecked(checkboxId){
var id ='#'+ checkboxId;
返回$(id).is(:checked);
}
在被困一天之后,我仍然不确定为什么我不能得到它的工作。请帮助解决方案
您的小提琴在我制作完成后运作3个修正:- jQuery的导入(左上方菜单)
- 缺少
isChecked
函数
- 使用道具而不是
attr
来选中复选框
- 缺少
I am trying to select all checkboxes on a page once the 'select all' checkbox is clicked and i am using jquery for this as you can see at the below link:
http://jsfiddle.net/priyam/K9P8A/
The code to select and unselect all checkbox is:
function selectAll() {
$('.selectedId').attr('checked', isChecked('selectall'));
}
function isChecked(checkboxId) {
var id = '#' + checkboxId;
return $(id).is(":checked");
}
After being stuck with it for a day, I am still not sure why I cant get it to work. Please help
解决方案
Your fiddle works after I made 3 fixes :
- import of jQuery (top left menu)
- addition of the missing
isChecked
function - use of prop instead of
attr
to check the boxes
这篇关于Jquery“选择所有”复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文