Javascript Last character missing on OnKeyPress event
function h(x)
{
alert(x);
}
<input onkeypress=h(this.value) type=text>
When I press 'a' alert empty
When I press 'b' after 'a' =>ab alert only 'a' and I want 'ab' When I type 'abc开发者_高级运维d' it alert 'abc' only and I want 'abcd'your event fires before letter is registered. you should use onkeyup event. It kicks-in after you release key
Javascript:
function h(x)
{
alert(x);
}
HTML Code:
<input onkeyup=h(this.value) type=text>
var unicode=e.keyCode? e.keyCode : e.charCode;
typing = document.getElementById('textbox').value + String.fromCharCode(unicode);
精彩评论