Cliche onBlur event and onfocus event of js
- 2021-07-02 23:12:56
- OfStack
The onFocus event is the event that occurs when the cursor falls in a text box.
The onBlur event is an event that occurs when the cursor loses focus.
You can make up the following examples
1.html
<HTML>
<HEAD>
<TITLE> Use onBlur Event handler </TITLE>
</HEAD>
<BODY BGCOLOR="lavender">
<FORM name="F1">
<INPUT TYPE=text NAME=text1 value="1111ONBLUR_green" ONBLUR="(document.bgColor='green')">
<INPUT TYPE=text NAME=text2 value="2222ONBLUR_black" ONBLUR="(document.bgColor='black')">
<INPUT TYPE=text NAME=text2 value="3333ONBLUR_yellow" ONBLUR="(document.bgColor='yellow')">
<br>
<p>
<INPUT TYPE=text NAME=text3 value="4444onfocus_blue" onfocus="(document.bgColor='blue')">
<INPUT TYPE=text NAME=text4 value="5555onfocus_red" onfocus="(document.bgColor='red')">
<INPUT TYPE=text NAME=text4 value="6666onfocus_orange" onfocus="(document.bgColor='orange')">
</FORM>
</BODY>
</HTML>
There are also the following examples
2.html
<!-- Document description: OnFocus Events -->
<!-- ------------------------------ -->
<html>
<head>
<title>OnFocus Events </title>
</head>
<body>
<Form>
<input type="text" name="test1" value="test1" onclick=alert(" You can turn it off !")>
<input type="text" name="test1" value="test1" onblur=alert(" You can turn it off aaaaaaa!")>
<input type="text" name="test1" value="test1" onclick=alert(" You can turn it off bbbbbbbbb!")>
<input type="text" name="test2" value="1 I can't turn it off if I press it, haha" onFocus=alert(" I became the focus of input !")>
</Form>
</body>
</html>