Here is code http://jsfiddle.net/8ZzER/26/
I try to call the function bound to keyup
but keyPres
variable is null
HTML
<inp开发者_StackOverflow中文版ut id="text" name="text" type="text" onkeyup="alert('Boom')"
value="Key up here"/>
<input type="button" id="fire" value="fire" />
JavaScript
document.getElementById("fire").onclick=function()
{
var textElement = document.getElementById("fire");
var keyPres= textElement.onkeyup;
keyPres.call();
}
Your handler is on the element with "id" value "text", but your code looks for "fire".
<input id="text" name="text" type="text" onkeyup="alert('Boom')"
value="Key up here"/>
<input type="button" id="fire" value="fire" />
The handler should look like:
// says "fire" in your jsFiddle
var textElement = document.getElementById("text");
var keyPres= textElement.onkeyup;
keyPres.call();
Well, you are assigning textElement
to your button (fire
) and not your text box.
http://jsfiddle.net/8ZzER/29/
精彩评论