开发者

Call JavaScript method on dynamic form element

开发者 https://www.devze.com 2022-12-13 19:23 出处:网络
I am creating new textbox us开发者_高级运维ing JavaScript. I want to call a JavaScript method onkeyup event of this newly created textbox. How will I do this?

I am creating new textbox us开发者_高级运维ing JavaScript. I want to call a JavaScript method onkeyup event of this newly created textbox. How will I do this?

Below is my code:

var element2 = document.createElement("input"); 
element2.type = "text"; 
element2.id='complete-field'+tableID;
element2.name=tableID;


Use addEventListener and attachEvent to attach events :

if (element2.addEventListener){
  element2.addEventListener('keyup', myFunction, false);
} else if (element2.attachEvent){
  element2.attachEvent('onkeyup', myFunction);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消