Javascript 引导表-无法在tr上添加单击事件
我正在使用引导表() 我正在尝试添加单击事件Javascript 引导表-无法在tr上添加单击事件,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我正在使用引导表() 我正在尝试添加单击事件 $('tr').click(function(){ console.log('test'); }); 但它不起作用。我知道bootstrap表库中有一个事件,但对我来说,与jQuery一起使用它是很重要的。您知道引导表源代码中阻止此事件的原因吗?我试图从bootstrap-table.js中删除所有“.off”,但没有效果。试试这个 $('table').on('click', 'tr' , function (event) { cons
$('tr').click(function(){ console.log('test'); });
但它不起作用。我知道bootstrap表库中有一个事件,但对我来说,与jQuery一起使用它是很重要的。您知道引导表源代码中阻止此事件的原因吗?我试图从bootstrap-table.js中删除所有“.off”,但没有效果。试试这个
$('table').on('click', 'tr' , function (event) {
console.log('test');
});
我认为您可以使用
onClickRow
或click row.bs.table
事件代替tr click事件,下面是和
代码示例:
// Fires when user click a row
$('#table').bootstrapTable({
onClickRow: function (row, $element) {
// row: the record corresponding to the clicked row,
// $element: the tr element.
}
});
// or
$('#table').on('click-row.bs.table', function (e, row, $element) {
// console.log(row, $element);
});
(我是Bootstrap Table的作者,希望能帮助您!)我已经尝试了这段代码,成功地找到了get-value-find-td(td:eq(1))
就在几天前,我开始使用这个有用的插件,我也遇到了同样的问题,用户wenyi给出了一个很好的答案,但对于那些刚开始使用的人来说有点复杂
/* You have this table */
<table id="my-table">
<tr>
<a href="#" class="my-link">Details</a>
</tr>
</table>
/* You have to options to detect this click (and more) */
/* Normal way */
$(".my-link").click(function(){
//do something
});
/* To solve this click detection problem you will need to use this */
$("#my-table").on('click','.my-link',function(){
//do something
});
你能创建一个提琴来重现这个问题吗?不确定,与OP尝试的相比会有什么变化…?请参见$('.table.clickable').bootstrapTable({});删除表中的所有内容!!
/* You have this table */
<table id="my-table">
<tr>
<a href="#" class="my-link">Details</a>
</tr>
</table>
/* You have to options to detect this click (and more) */
/* Normal way */
$(".my-link").click(function(){
//do something
});
/* To solve this click detection problem you will need to use this */
$("#my-table").on('click','.my-link',function(){
//do something
});
/* Even you can use this method, but the performance is less */
$(document).on('click','.my-link',function(){
//do something
});