将属性链接到创建它的元素 [英] Linking a attribute to element it is created

查看:79
本文介绍了将属性链接到创建它的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

我希望在javascript创建元素时将事件''onchange''链接到元素。我知道javascript有函数''setAttribute'',而jquery有''attr''函数。我希望无论何时创建新元素页面都没有加载,属性链接到该元素并且我知道该元素的id提前

我想这样做,因为我无法控制元素的创建,但我知道该元素创建的id。我希望每当这个元素创建一个属性时都链接到它''' onchange''

如果有人有任何解决方案请告诉我

Dear Sir,
i want to link a event ''onchange'' to a element when the element is created by javascript. I know javascript have function ''setAttribute'', and jquery have ''attr'' function.i want whenever the new element is created page is not loaded , an attribute is linked to that element with considation i know the id of that element in advance
I want to do this because i have no control to the creation of element but i know the id with which that element created.i want whenever this element create a attribute is linked to it ''onchange''
if any one have any solution plz let me know

推荐答案

使用jQuery非常方便:

It''s very conveniently done with jQuery:
myElement = // create it as you already do
myElement.change(function() {
   // handle the event here
});





如果你需要学习jQuery(强烈推荐),请参阅:

http://en.wikipedia.org/wiki/ JQuery [ ^ ],

http://jquery.com/ [ ^ ],

http://learn.jquery.com/ [ ^ ],

http://learn.jquery.com/using-jquery-core/ [ ^ ],

http://learn.jquery.com/about-jquery/how-jquery-works/ [ ^ ](从这里开始)。



-SA



If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://learn.jquery.com/[^],
http://learn.jquery.com/using-jquery-core/[^],
http://learn.jquery.com/about-jquery/how-jquery-works/[^] (start from here).

—SA


这篇关于将属性链接到创建它的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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