开发者

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);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜