Following my code:
HTML:
<input id="test" onkeydown="test();" type="text"/>
JS:
function pl(id){
return id;
}
function test(){
id = "test";
alert(pl(id));
}
Why the browser return TypeError: test is not a function?
Following my code:
HTML:
<input id="test" onkeydown="test();" type="text"/>
JS:
function pl(id){
return id;
}
function test(){
id = "test";
alert(pl(id));
}
Why the browser return TypeError: test is not a function?
There isn't a problem with the code in the question, but the live example of the code you provided, has your function definitions wrapped in another function (which is executed onload).
They are scoped to their containing function, so you cannot access them with an onclick attribute (which can only touch global variables).
Bind your event handlers programatically instead.
document.getElementById('test').addEventListener(
"keydown",
test
);
For example: http://jsfiddle.net/9tFHA/2/