开发者

Failed to set event handler

This question is a follow up of post Failed to set event handler in javascript

I want to add an event handler for input text controls. The input box control is generated dynamically. My code is like:

_inputbox = document.createElement("input");
_inputbox.type = "text";
_inputbox.id = settings[zindex];
_inputbox.onblur = checkName; 

checkName() is defined previously. But when I input something in the box and move the focus to other control, the checkName() isn't executed.

In the DOM tab of Firebug, I find the onblur is assigned to checkName() correctly.

In the HTML tab of Firebug, I find the input box only defines an "ID" and a "type". No onblur开发者_如何转开发 in its HTML code. If I edit the HTML and add onblur=checkName() manually. The function can be called successfully.

HTML code

<input type="text" id="Datastore">

Is there anyone can help me?


Try

If(_inputbox.addEventListener) {
    _inputbox.addEventListener('blur', checkName, false);
} else { 
    _inputbox.attachEvent('onblur', checkName);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜