如何在jquery中为动态添加html控件分配事件 [英] How to assign events in jquery for the dynamically adding html controls

查看:83
本文介绍了如何在jquery中为动态添加html控件分配事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Folks,



如何在jquery中为动态添加html控件分配事件。



例如:



我已经在DOM中添加了一些控件。

Hi Folks,

How to assign events in jquery for the dynamically adding html controls.

For example:

I have added some control in DOM ready.

$(document).ready(function(){
...
     $(obj).each(function(){
          str += "<input id='txt" + ID + "' type='text' title='" + Text + "' /></li>" //Here adding the control
          ...
          //Here I want to add some event
          $("#txt" + ID).change(function(){
             ...
             ...
             ...
          });
     });
});





如果我调试我没有得到语句的对象$(#txt+ ID)



帮助我失踪的地方。



谢谢。



If I debug I am not getting the object for the statement $("#txt" + ID)

Help me where I am missing.

Thanks.

推荐答案

(document).ready(function(){
...
(document).ready(function(){ ...


(obj).each(function(){
str + =< input id ='txt+ ID +'type ='text'title ='+ Text +'/>< / li>//这里添加控件
...
//这里我要添加一些事件
(obj).each(function(){ str += "<input id='txt" + ID + "' type='text' title='" + Text + "' /></li>" //Here adding the control ... //Here I want to add some event


(#txt+ ID).change(function(){
...
...
...
});
});
});
("#txt" + ID).change(function(){ ... ... ... }); }); });





如果我调试我没有得到声明的对象



If I debug I am not getting the object for the statement


这篇关于如何在jquery中为动态添加html控件分配事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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