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);
}
精彩评论