html代码如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>全选</title> </head> <body> <ul> <li><input id="all" type="checkbox" autocomplete="off"></li> <li><input type="checkbox" name="groupId" value="2"></li> <li><input type="checkbox" name="groupId" value="2"></li> <li><input type="checkbox" name="groupId" value="2"></li> </ul> </body> </html>
js代码如下:
$("#all").click(function(event) { if(this.checked) { $(‘input[name=groupId]‘).each(function() { this.checked = true; }); }else{ $(‘input[name=groupId]‘).each(function() { this.checked = false; }); } });
时间: 2024-10-06 03:42:52