单击事件上的HTML复选框未触发动态控制 [英] HTML Check Box on click event is not triggering for dynamic control
问题描述
我正在从组中获取用户详细信息,并将这些值绑定到html表中.
I am getting user details from the group and binding those values in the html table .
在这里,我正在动态生成HTML表,并且在第一列中也包含了复选框(输入类型="复选框" id ="chk1"/>).
Here I am generating the HTML table dynamically and included check box as well (<input type="checkbox" id="chk1" /> ) at the first column.
我使用ID来执行某些事件,从而在点击时为复选框编写了代码.但它不会触发...
I wrote the code for checkbox on click using ID to execute some event. but it is not triggering...
但是当我使用静态控件进行测试时,相同的代码仍在工作.
But the same code is working when I tested with the static control.
请分享您的想法.
推荐答案
我们可以使用on()方法来实现它.
We can use on() method to achieve it.
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
(文档).ready(function(){
(document).ready(function(){
(文档).on (点击",#chk1",function(){ 警报("chk1点击"); }); }); </script>
(document).on("click", "#chk1" , function() { alert("chk1 click"); }); }); </script>
我们还可以创建一个JavaScript函数,并为复选框"的onclick属性设置此方法.动态生成HTML表时使用html标签.
We can also create a JavaScript function and set this method for onclick attribute of "checkbox" html tag when generating the HTML table dynamically.
<input type="checkbox" id="chk1" onclick="CustomMethod()"/>
最好的问候,
丹尼斯
这篇关于单击事件上的HTML复选框未触发动态控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!