function h(x)
{
alert(x);
}
<input onkeypress=h(this.value) type=text>
当我按“a”时,警报为空
当我在“a”之后按“b”时 =>ab 警报只有“a”,我想要“ab”
当我输入“abcd”时,它只警报“abc”,我想要“abcd”
function h(x)
{
alert(x);
}
<input onkeypress=h(this.value) type=text>
当我按“a”时,警报为空
当我在“a”之后按“b”时 =>ab 警报只有“a”,我想要“ab”
当我输入“abcd”时,它只警报“abc”,我想要“abcd”
您的事件在信件注册之前触发。你应该使用onkeyup 事件。它在您释放密钥后启动
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);