JS onblur and onkeyup Event usage

Source: Internet
Author: User

1.onblur is called when the focus is lost;

2.onkeyup means that the keyboard occurs after each character is entered. Simply put, the button on the keyboard is triggered when it is released.

Example:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title> Input Amount diy-bgy2014-11-22</title>
<script type= "Text/javascript" language= "JavaScript" src= "Jquery-1.2.6.js" ></script>
<script type= "Text/javascript" >
function Check (v)
{
if (v.substring (0,1) ==0 && v.length!=0)
{
$ ("#money"). Val ("");
Alert ("Please enter the amount correctly!") ");
$ ("#money"). focus ();
}
Else
{
$ ("#money"). focus ();
}
}
</script>
<style type= "Text/css" >
. Bg{width:100%;height:100%;background: #CCE8CF;}
</style>
<body class= "BG" >
Please enter the amount: <input type= "text" id= "Money" style= "Width:150px;height:50px;font-size:36px;color: #ff7f00; Font-weight: Bold;background-color:eeeeee "onkeyup=" This.value=this.value.replace (/[^\d]/g, ') "onblur=" Check (this.value) " > RMB </input>
</body>

In this example, the onkeyup event is triggered as soon as the keyboard is entered, and the non-numeric input is replaced with a null character (not a space). When the input is all numbers, and the mouse moves away when the trigger onblur and call check.

JS onblur and onkeyup Event usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.