选中所有功能复选框
在下面的代码中,我试图实现全选功能。当我点击全选复选框时,名为 sts 的复选框没有被选中。我做错了什么
$(document).ready(function() {
$("#selectall").click(function()
{
var checked_status = this.checked;
$(".sts").each(function()
{
this.checked = checked_status;
});
});
});
var ele1 ='<table cellpadding="0" cellspacing="0" border="1" ><tr><th style="width:100px;" ><p align="center">Select all students</p><p align="center"><input type="checkbox" name="sts" class="sts" id="selectall" /></p></th><th><p align="center">Student name</p></th><th><p align="center">Select Grade</p></th><th><p align="center">Certificates</p></th></tr>';
for(var l=0;l<data.studentarr.length;l++)
{
ele1 += '<tr id="s_r_' + data.studentarr[l].id + '" class="students1"><td align="center" style="width:100px;"><input type="checkbox" class="sts" name="sts" /></td><td align="center">' + data.studentarr[l].name +'</td><td align="center">' + getgrade_values(data.studentarr[l].id) + '</td><td>' + data.studentarr[l].download_link + '</td></tr>';
}
ele1 += "</table>";
$('#student_table').append(ele1);
In the below code i am trying to implement the selectall functionality.when i clcik on select all checkbox the checkbox named sts is not getting selected.what am i doing wrong
$(document).ready(function() {
$("#selectall").click(function()
{
var checked_status = this.checked;
$(".sts").each(function()
{
this.checked = checked_status;
});
});
});
var ele1 ='<table cellpadding="0" cellspacing="0" border="1" ><tr><th style="width:100px;" ><p align="center">Select all students</p><p align="center"><input type="checkbox" name="sts" class="sts" id="selectall" /></p></th><th><p align="center">Student name</p></th><th><p align="center">Select Grade</p></th><th><p align="center">Certificates</p></th></tr>';
for(var l=0;l<data.studentarr.length;l++)
{
ele1 += '<tr id="s_r_' + data.studentarr[l].id + '" class="students1"><td align="center" style="width:100px;"><input type="checkbox" class="sts" name="sts" /></td><td align="center">' + data.studentarr[l].name +'</td><td align="center">' + getgrade_values(data.studentarr[l].id) + '</td><td>' + data.studentarr[l].download_link + '</td></tr>';
}
ele1 += "</table>";
$('#student_table').append(ele1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在动态创建全选复选框,因此您应该使用 live 或 delegate 绑定点击事件。
试试这个:
You are dynamically creating the select all check box, hence you should use live or delegate to bind the click event.
Try this: