繁体   English   中英

如何从引导表获取td单击事件?

[英]How get td click event from bootstrap table?

我正在尝试将事件归因于我的引导表的differents列的单元格。

问题是:尽管我为每个列都设置了一个类,但是不会触发归于此类的事件。 我仍然尝试为在单元格中添加的每个div设置一个类,但是它的事件也没有触发。

那么,如何使用bootstrab表获取td事件?

在向我们展示一些代码之前,您可以尝试一下,

$('body').on('click', '#tableID tr td', function(){
  //whenever any td is clicked, this function will get called
});

您可以使用想要与td绑定的任何事件名称来更改'click'

我将事件委派给主体,因为如果您将表元素动态添加到html中,则直接绑定到这些事件将不会生效。

这是引导表的td click事件的完整代码

 $(document).ready(function(){ $('table td').click(function(){ alert($(this).html()); }); }); 
 <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <p>Click on the td below</p> <table class="table"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>john@example.com</td> </tr> <tr> <td>Mary</td> <td>Moe</td> <td>mary@example.com</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>july@example.com</td> </tr> </tbody> </table> </div> </body> </html> 

尝试这个

$("#boottable").on('all.bs.table', function (e, name, args) {
            console.log(name, args);
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM