我要求不使用 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/