Home >
Web Front-end >
JS Tutorial >
Judgment code for text box to gain focus and lose focus_Form special effects
Judgment code for text box to gain focus and lose focus_Form special effects
WBOY
Release: 2016-05-16 17:54:58
Original
1684 people have browsed it
The text box loses focus event and gains focus event
onBlur: This event is generated when the input focus is lost. onFocus: The file is generated when the input focus is gained. Onchange: When the text value changes, this event is generated Onselect: When the text is highlighted, the file is generated onpropertychange When the property changes, this event is generated Regardless of pasting keyup onchange, etc., it is the most sensitive
First let’s look at the javascript written directly on the input
< ;script> function tt(){ var i=document.form1.text1.value;
if(i.length>=6) document.getElementById("s1" ).innerHTML="Username cannot be greater than 6 characters"; else document.getElementById("s1").innerHTML=""; } function a(){ var j=document.form1.text2.value; if(j.length>=6) document.getElementById("s2").innerHTML="Password cannot be greater than 6 characters" else document.getElementById("s2").innerHTML=""; }
html>
First type: html5
html5 adds several new attributes to the form text box, such as: email, tel, number, time, required, autofocus, placeholder, etc. These attributes bring great changes to the form effect. Placeholder is one of them, it can complete the text box gaining focus and losing focus at the same time. It must be ensured that the value of the input is empty, and the content of the placeholder is what we see on the page. The code is as follows:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn