jQuery keyup事件

jQuery keyup is one of the keyboard event methods. Other jQuery keyboard event methods are keydown() and keypress().

jQuery keyup是键盘事件方法之一。 其他jQuery键盘事件方法是keydown()keypress()

jQuery键盘 (jQuery keyup)

jQuery keyup method triggers when you release the pressed key. You can attach functions to execute when this event occurs.

当您释放按下的键时,jQuery keyup方法将触发。 您可以附加函数以在发生此事件时执行。

jQuery keyup方法语法 (jQuery keyup method syntax)

  1. keyup(): This jQuery keyup method is used without any arguments.

    keyup():此jQuery keyup方法使用时不带任何参数。
  2. keyup(handler): This jQuery keyup method attaches a function to be executed when the keyup event is fired.

    keyup(handler):此jQuery keyup方法附加了在触发keyup事件时要执行的功能。

jQuery keyup示例 (jQuery keyup example)

Following example demonstrates the use of jQuery keyup method.

以下示例演示了jQuery keyup方法的用法。

jquery-keyup.html

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><br>
Type something above, after key up background color will change to Red.
<br><br>
Click on Reset button to try again.
</body>
</html>

In above example, when the key is up, keyup() method is triggered which in turn executes the function that changes the background colour to red.

在上面的示例中,当按下键时,将触发keyup()方法,该方法又执行将背景色更改为红色的功能。

Below screencast shows above jQuery keyup example in action.

下面的截屏视频显示了上面的jQuery键盘操作示例。

jQuery keyup演示 (jQuery keyup demo)

演示地址

翻译自: https://www.journaldev.com/4967/jquery-keyup-event

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值