是否可在用户按压 HTML 中按键时执行脚本?
使用 onkeydown 属性。当用户按压按键时,将触发 onkeydown 属性。
示例
你可以尝试运行以下代码,以便在按压按键时执行脚本:−
<!DOCTYPE html>
<html>
<body>
<p>Press a key inside the textbox.</p>
<input type = "text" onkeydown = "display()">
<script>
function display() {
alert("You pressed a key!");
}
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP