我目前在 bootstrap table
中将此代码用于 row click
事件
$('#myTable').bootstrapTable().on('click-row.bs.table', function (e, row, $element)
{
//....my operation
}
问题是这会触发整行,我希望能够为单个单元格触发它。
Note I am using the arguments,
row and $element
这是 FIDDLE
最佳答案
$element是整行,这样你无法知道点击了哪个单元格, Bootstrap 表没有单元格点击事件,所以你需要在最后一个单元格上手动添加点击事件并自己填写你需要的变量
$('#table').bootstrapTable({
data: data
}).on('click','td:last-child',function(){
var $t = $(this), $row = $t.parent(), i = $row.index(), row = data[i];
var $firstTd = $row.children().eq(0);
if($firstTd.data("haveTable") !== true){
$firstTd.data("haveTable",true);
$firstTd.append('<table class="newTable"><tr><td>NEW TABLE</td></tr></table>');
} else {
$firstTd.data("haveTable",false);
$firstTd.children("table").remove();
}
});
关于javascript - 单击单元格上的事件而不是整行 - 使用 FIDDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30329561/