gpt4 book ai didi

javascript - onkeypress 事件监听器不工作

转载 作者:行者123 更新时间:2023-11-28 11:25:44 32 4
gpt4 key购买 nike

我要求不使用 html 事件处理程序。所以我试图从 script 处理它。我做了一个小功能,但它不起作用

<head>
<script type="text/javascript">
function lld () {
document.getElementById('me').onkeypress= myfunction()
}

function myfunction(){
alert('hiiiii')
}

</script>
</head>
<body>
<input type="text" id="me" />
</body>
</html>

最佳答案

试试这个

document.getElementById('me').onkeypress= myfunction;

function myfunction(){
alert('hiiiii');
}

关于javascript - onkeypress 事件监听器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13117197/

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