onkeyup event


onkeyup Event

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function myFunction(){
	var x=document.getElementById("fname");
	x.value=x.value.toUpperCase();
}
</script>
</head>
<body>

<p>当用户在输入字段释放一个按键时触发函数。函数将字符转换为大写。</p>
输入你的名称: <input type="text" id="fname" onkeyup="myFunction()">

</body>
</html>

Run Instance»

Click "Run instance" button to view the online instance


Definition and usage

The onkeyup event occurs when the keyboard key is released.

Tips: The sequence of events related to the onkeyup event:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Syntax

HTML:

<elementonkeyup="SomeJavaScriptCode">

In JavaScript:

##object.onkeyup=function(){SomeJavaScriptCode};

ParametersDescriptionRequired. Specifies the JavaScript to be executed when this event occurs.
SomeJavaScriptCode


Browser support

QQ截图20161108165429.png##All major browsers support the onkeyup event

HTML tags that support onkeyup events:

The onkeyup attribute can be applied to all HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.