Bootstrap表 - 无法在tr上添加click事件 [英] Bootstrap table - cannot add click event on tr
问题描述
我正在使用Bootstrap表( http://wenzhixin.net .cn / p / bootstrap-table / docs / index.html )
I'm using Bootstrap table (http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html)
我正在尝试添加点击事件
I'm trying to add click event
$('tr').click(function(){ console.log('test'); });
但不起作用。我知道bootstrap-table库中有事件,但对我来说,使用jQuery的.click非常重要。你知道什么在bootstrap-table源代码中阻止了这个事件?我试图从bootstrap-table.js中删除所有.off,但它没有帮助。
but it doesn't work. I know that there is event in bootstrap-table library, but it's important for me to use it exactly with jQuery's .click. Do you know what is blocking this event in bootstrap-table source code? I tryied to remove all ".off"s from bootstrap-table.js, but it didn't help.
推荐答案
我认为你可以使用 onClickRow
或 click-row.bs.table
事件而不是tr click事件,这里是文档和例子。
I think you can use the onClickRow
or click-row.bs.table
event instead of the tr click event, here is the documentation and examples.
代码示例:
// 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的作者,希望能帮到你!)
(I am the author of Bootstrap Table, hope to help you!)
这篇关于Bootstrap表 - 无法在tr上添加click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!