[英]Select all textboxes using jQuery
I have code which displayed a person's info in a table(fields:name, surname, address, etc.) and one of the inputs is a checkbox.我有代码在表格中显示一个人的信息(字段:姓名、姓氏、地址等),其中一个输入是复选框。 The code is as follows:
代码如下:
$("#table").append('<tr class="trow'+j+'">'+
'<td class="ids" id="z'+i+'">'+totrecs+'</td>'+
'<td>'+member[i].jdate+'</td>'+
'<td class="users"
'<td id="contact'+i+'">'+member[i].fname+' '+member[i].lname+'</td>'+
'<td id="myaddress'+i+'">'+member[i].address1+' '+member[i].town+'</td>'+
'<td><input type="checkbox" name="whome" id="showMe'+i+'"'+
'class="boxes" onclick="getMe('+i+')" /></td></tr>');
totrecs++;
j++;
}
What I am tryin to do is program a function that when clicking a certain button all of the checkboxes will be selected/checked.我想要做的是编写一个函数,当单击某个按钮时,所有复选框都将被选中/选中。
I would appreciate any help.我将不胜感激任何帮助。 Thank You.
谢谢你。
<input type="button" value="Check/Uncheck All" />
$('#btnId').on('click', function() {
var check = false;
if( !$(this).hasClass('checked')){
bool = true;
}
$(this).toggleClass('checked');
$('#table input[type="checkbox"]').prop('checked', check)
});
这可能会有所帮助: JQquery 选择所有复选框教程
To check all checkboxes in #table
using jQuery:使用 jQuery 检查
#table
所有复选框:
$('#table :checkbox').attr('checked', '');
Note that this will not trigger any click events you set for the checkboxes.请注意,这不会触发您为复选框设置的任何点击事件。 You should use the
change
event instead of click
to make it happen as expected.您应该使用
change
事件而不是click
以使其按预期发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.