gpt4 book ai didi

Javascript onkeydown 函数

转载 作者:行者123 更新时间:2023-11-30 14:26:26 27 4
gpt4 key购买 nike

function Test(event) {
console.log(event.key + ' ' + event.which + ' ' + event.code);
}
<input type="text" onkeydown="Test(this)">

结果:

undefined undefined undefined

原因:我使用这种方法是因为我需要在运行时生成多个输入文本(动态)。

请任何人帮助我,在此先感谢。

最佳答案

你需要传递event而不是this

function Test(event) {
console.log(event.key + ' ' + event.which + ' ' + event.code);
}
<input type="text" onkeydown="Test(event)">

关于Javascript onkeydown 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51870395/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com