如何从bootstraptable获取td点击事件?
How get td click event from bootstrap table?
我正在尝试将事件归因于我 bootstrap table 的不同列的单元格。
问题是:虽然我已经为每一列设置了一个 class,但是归因于这个 class 的事件没有被触发。我仍然尝试为单元格中添加的每个 div 设置一个 class,但它的事件也没有被触发。
那么,如何使用 bootstrab table 获取 td 事件?
在您向我们展示一些代码之前,您可以试试这个,
$('body').on('click', '#tableID tr td', function(){
//whenever any td is clicked, this function will get called
});
您可以将 'click'
更改为您想绑定 td 的任何事件名称。
我将事件委托给正文,因为如果您将 table 元素动态添加到 html,直接绑定到这些事件将不会 fire/work.
这是用于引导程序的 td 点击事件的完整代码 table
$(document).ready(function(){
$('table td').click(function(){
alert($(this).html());
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<p>Click on the td below</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
试试这个
$("#boottable").on('all.bs.table', function (e, name, args) {
console.log(name, args);
});
我正在尝试将事件归因于我 bootstrap table 的不同列的单元格。
问题是:虽然我已经为每一列设置了一个 class,但是归因于这个 class 的事件没有被触发。我仍然尝试为单元格中添加的每个 div 设置一个 class,但它的事件也没有被触发。
那么,如何使用 bootstrab table 获取 td 事件?
在您向我们展示一些代码之前,您可以试试这个,
$('body').on('click', '#tableID tr td', function(){
//whenever any td is clicked, this function will get called
});
您可以将 'click'
更改为您想绑定 td 的任何事件名称。
我将事件委托给正文,因为如果您将 table 元素动态添加到 html,直接绑定到这些事件将不会 fire/work.
这是用于引导程序的 td 点击事件的完整代码 table
$(document).ready(function(){
$('table td').click(function(){
alert($(this).html());
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<p>Click on the td below</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
试试这个
$("#boottable").on('all.bs.table', function (e, name, args) {
console.log(name, args);
});