gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:01 26 4
gpt4 key购买 nike

我目前在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com