One. Onfocus (focus to the event)
When a text box has focus, the text inside it as "a good 123" Baidu search on the site as all the input box is automatically selected, this operation can be achieved using onfocus.
The following text box, when the mouse pointer moved over time, which have all been selected text:
This is how to do it? See the following code and explain:
<input type="text" name="url" value="http://www.gxblk.com" size="30" onmousemove="this.focus();this.select();">
Code, input tag embedded in the onmousemove (the mouse pointer over) the event JS statement, the equal sign after the this.focus () means the focus of its own; the focus of the logo is the text input cursor box will appear, but let it all be selected within the text, we have to spend this.select () statement, it means that the text box to select all the text.
II. Onblur (lost focus event)
We often will detect whether the text box has been entered correctly detect the user normally after clicking the submit button, in fact, the use of control loses focus, we can carry out the testing work in real time, this is the case, onblur event to send in handy.
The following example has four text boxes, if you do not have any click any one of them the operation, then nothing will happen, but when you click any one of them to have a focus (input cursor inside), if not entered anything and click somewhere else so that it loses focus, it will pop up a warning, give it a try -
Here is the code and explanation:
Form Code -
<form name="blur_test"> <p> Name <input type="text" name="name" value="" size="30"><br> Sex <input type="text" name="sex" value="" size="30"><br> Age <input type="text" name="age" value="" size="30"><br> Residential address <input type="text" name="addr" value="" size="30"></p> </form>
JS code -
Code form, each side frame of the code embedded in a onblur JS statement, they call JS code behind the custom function chkvalue (this), meaning that when the text box loses focus is called chkvalue () function ; this chkvalue () function to detect the text box is empty, if it is to pop up a warning window. This function has a parameter (txt), corresponding to a text box in front of the parameters of the function call (this) is itself.