搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
jQuery 教程
jQuery 基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>jQuery keydown事件示例 - 基础教程(div.cn)</title> <head> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").keydown(function(event){ $(this).css("background-color", "yellow"); $("span").text(event.type); }); $("input").keyup(function(event){ $(this).css("background-color", "lightblue"); $("span").text(event.type); }); }); </script> </head> <body> <p>在下面的输入字段中输入内容。 它将在击键和击键时更改背景颜色。</p> <p>输入内容:<input type="text"> </p> <p>事件类型:<span style="color:red;"> </span> </p> </body> </html>
运行结果