当用户按键盘上的键时运行脚本如何执行?
使用 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
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP