jQuery DataTables 是一个非常流行的 jQuery 插件,用于增强 HTML 表格的功能,如分页、即时搜索和多列排序等。行详细信息模式(Row Details)允许你展开表格行以显示更多信息。
如果你想在单击行按钮时抑制行详细信息模式,可以通过以下步骤实现:
要在单击行按钮时抑制行详细信息模式,可以通过以下步骤实现:
以下是一个完整的示例,展示了如何在单击行按钮时抑制行详细信息模式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DataTables Example</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
</head>
<body>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
<td><button class="row-button">Click Me</button></td>
</tr>
<!-- 其他行数据 -->
</tbody>
</table>
<script>
$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on('click', '.row-button', function(e) {
e.stopPropagation();
alert('Button clicked!');
});
$('#example tbody').on('click', 'tr', function(e) {
if ($(e.target).hasClass('row-button')) {
return false;
}
});
});
</script>
</body>
</html>
通过这种方式,你可以有效地抑制行详细信息模式,并在单击行按钮时执行自定义逻辑。
没有搜到相关的沙龙