javascript - 单击单元格上的事件而不是整行 - 使用 FIDDLE

标签 javascript jquery twitter-bootstrap css twitter-bootstrap-3

我目前在 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();
    }
});

https://jsfiddle.net/e3nk137y/1663/

关于javascript - 单击单元格上的事件而不是整行 - 使用 FIDDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30329561/

相关文章:

javascript - 当不在页面顶部时滚动到顶部按钮显示

javascript - 如何在TinyMCE 3中隐藏图像描述对话框?

javascript - 如何创建带背景重复的梯形div

javascript - 在特定页面上包含 Adsense

javascript - Bootstrap JS 选项卡中的定时选项卡切换

html - 在 Bootstrap CSS 中将列表居中

javascript - 如何在提交时正确组合两个功能

javascript - 从另一个函数清除间隔

jquery - 获取单选按钮组的值

javascript - jQuery touchSwipe内容滚动功能