jQuery keyup事件
时间:2020-02-23 14:46:11 来源:igfitidea点击:
jQuery keyup是键盘事件方法之一。
其他jQuery键盘事件方法是keydown()
和keypress()
。
jQuery键盘
释放按键时,jQuery keyup方法将触发。
您可以附加函数以在发生此事件时执行。
jQuery keyup方法语法
keyup():此jQuery keyup方法使用时不带任何参数。
keyup(handler):此jQuery keyup方法附加了在触发keyup事件时要执行的功能。
jQuery keyup示例
以下示例演示了jQuery keyup方法的用法。
jquery-keyup.html
<!DOCTYPE html> <html> <head> <title>jQuery keyup event example</title> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(document).ready(function(){ $("input:text").keyup(function(){ $("input:text").css("background-color","red"); }); //reset jQuery keyup css $("input:reset").click(function(){ $("input:text").css("background-color","white"); }); }); </script> </head> <body> <h3>jQuery keyup example</h3> Enter anything: <input type="text"> <input type="reset"> <br> Type something above, after key up background color will change to Red. <br> Click on Reset button to try again. </body> </html>
在上面的示例中,当按下键时,将触发keyup()方法,该方法又执行将背景色更改为红色的功能。