【发布时间】:2020-11-20 06:44:19
【问题描述】:
我有一个包含一些 json 数据的数据表。我在每一行中添加了一个复选框,但问题是我想一次选择一行。即当我单击一行上的复选框时,其他复选框不会被选中。即表现得像一个单选按钮。我的代码哪里出错了。 表
<div>
<h1>Accounts Table</h1>
<table id="employeesTable" class="display">
<!-- Header Table -->
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Amount</th>
<th>Date</th>
<th>Description</th>
<th>Active</th>
</tr>
</thead>
<!-- Footer Table -->
<tfoot>
<tr>
<th>Id</th>
<th>Name</th>
<th>Amount</th>
<th>Date</th>
<th>Description</th>
<th>Active</th>
</tr>
</tfoot>
</table>
</div>
jQuery 数据表
$(document).ready( function () {
var table = $('#employeesTable').DataTable({
"sAjaxSource": "/account/list",
"sAjaxDataProp": "",
"order": [[ 0, "asc" ]],
"aoColumns": [
{ "mData": "id"},
{ "mData": "account_type" },
{ "mData": "amount" },
{ "mData": "date" },
{ "mData": "description" },
{ "mData": null,
className: "center",
defaultContent:'<input type="checkbox" name="name1"/>' }
]
}
)
$('input[name="name1"]').on('change', function() {
var checkedValue = $(this).prop('checked');
// uncheck other checkboxes (checkboxes on the same row)
$(this).closest('tr').find('input[name=""]').each(function(){
$(this).prop('checked',false);
});
$(this).prop("checked",checkedValue);
});
【问题讨论】:
标签: javascript html jquery ajax