如何检查jquery中的所有行?很难在这里解决
它在tbody ->第2 td ->输入:复选框中找到
我只知道如何单选复选框,$('.myCheckbox').prop('checked', true);,但每一行和循环,我有一个艰难的时间。能给我点建议吗?
发布于 2020-03-24 03:31:46
要检查所有checkboxes,可以使用以下代码:
$('button').on("click", function(){
$("table input[type='checkbox']").each(function(){
$(this).attr('checked', 'checked');
//When you want to uncheck
$(this).removeAttr('checked');
});
return false;
});希望这将有助于理解这个概念。
发布于 2020-03-24 03:46:02
在表中查找所有复选框,并在单击位于第一行的selectAll复选框时更改选中状态。
$('#selectAll').change(function() {
var checkboxes = $(this).closest('table').find(':checkbox');
checkboxes.prop('checked', $(this).is(':checked'));
});<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="bs-example">
<table class="table table-striped">
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input type="checkbox" id="selectAll" /></td>
<td>Kent</td>
<td>clarkkent@mail.com</td>
</tr>
<tr>
<td>2</td>
<td><input type="checkbox" name="select[]" /></td>
<td>Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>3</td>
<td><input type="checkbox" name="select[]" /></td>
<td>Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td><input type="checkbox" name="select[]" /></td>
<td>Rtyer</td>
<td>yuioo@mail.com</td>
</tr>
</tbody>
</table>
</div>
发布于 2020-03-24 03:46:42
给你一个解决办法
$("button").click(function() {
$('input[type="checkbox"]').each(function() {
$(this).prop("checked", true);
});
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>Row 1</td>
<td>
<input type="checkbox" class"my-checkbox" />
</td>
</tr>
<tr>
<td>Row 2</td>
<td>
<input type="checkbox" class"my-checkbox" />
</td>
</tr>
<tr>
<td>Row 3</td>
<td>
<input type="checkbox" class"my-checkbox" />
</td>
</tr>
<tr>
<td>Row 4</td>
<td>
<input type="checkbox" class"my-checkbox" />
</td>
</tr>
</tbody>
</table>
<button>Click ME</button>
如果您的输入复选框是动态生成的,请使用螺旋桨检查和取消复选框。
https://stackoverflow.com/questions/60824166
复制相似问题