<table>
<tr>
<td>
<div>
<input type="checkbox" id="home1">Home1</input>
<input type="checkbox" id="home2">Home3</input>
<input type="checkbox" id="home3">Home3</input>
<input type="checkbox" id="home4">Home4</input>
</div>
</td>
<td id="selectedhome"> </td>
</tr>
</table>
<input type="button" value="Select" />
在上面的代码中单击按钮,复选框的所有选中的值都应出现在selectedhome td中,旁边有一个撤消链接,并且从第一个td不可见。选中撤消按钮复选框应该返回到初始位置。如何使用jquery
实现这一目标答案 0 :(得分:2)
试一试。它会将每个复选框重置为加载页面时的默认选中值。
示例: http://jsfiddle.net/6kFMk/1/
// Display ID value of checked boxes
$('input[value=Select]').click(function() {
var values = $('table :checkbox:checked').map(function() {
return this.id;
}).get().join(',');
var home = $('#selectedhome').text(values);
});
// Reset checkboxes to initial state
$('input[value=Undo]').click(function() {
$('table :checkbox').each(function() {
this.checked = this.defaultChecked;
});
});