如何在HTML表上动态添加单击事件 [英] How to dynamically add a click event on a HTML table

查看:118
本文介绍了如何在HTML表上动态添加单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态创建了一个HTML表。它很好地显示了数据。现在我想添加一个click事件来选择该表的一行。怎么能动态完成?我找不到合适的源代码。如果你知道,你可以分享信息吗?谢谢。



我尝试了什么:



如何动态添加HTML表格上的点击事件

解决方案

请试试这个:



 


('body')。on('click','< tabled_id>',function(){
//做点什么
});
< / tabled_id>





在DOM中形成表格后,调用上面的方法并执行您需要的操作。



参考: - javascript - 在jQuery中,如何将事件附加到动态html元素? - 堆栈溢出 [ ^ ]



希望这有助于您找到解决方案:)。


I created a HTML table dynamically. It displays the data well. Now I want to add an click event to select a row of this table. How can it be done dynamically? I can't find proper source code for it. If you know, could you share the info? Thanks.

What I have tried:

How to dynamically add a click event on a HTML table

解决方案

Please try this :


('body').on('click', '<tabled_id>', function() { // do something }); </tabled_id>



After forming the table in the DOM, call the above method and do the operation you need.

Ref :- javascript - In jQuery, how to attach events to dynamic html elements? - Stack Overflow[^]

Hope this will help you to find the solution :).


这篇关于如何在HTML表上动态添加单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆