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