JQuery focus and blur events application details
- 2020-03-30 01:28:32
- OfStack
One, demand reasons
The following is required when filling out the form
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201401/20140126095840.png ">
Two, concrete implementation
The following is required when filling out the form
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201401/20140126095840.png ">
Two, concrete implementation
<!DOCTYPE html PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=UTF-8">
<title> Mouse click after no text, move the mouse after text </title>
<script language="JavaScript"src="../jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#account").focus(function(){
varoldValue = $(this).val();
if(oldValue == this.defaultValue){
$(this).val("");
}
});
$("#account").blur(function(){
alert("12");
varoldValue = $(this).val();
if(oldValue == ""){
$(this).val(this.defaultValue);
}
});
});
</script>
</head>
<body>
Account: <input id="account"name="account" type="text" value=" Please enter account number ">
</body>
</html>