Home >Web Front-end >JS Tutorial >Methods to control the display and hiding of prompt information in the input box_javascript skills

Methods to control the display and hiding of prompt information in the input box_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:00:212779browse

When using html css javascrpt to create pages, we often encounter some small details that affect the user experience and are easily overlooked by us. For example, how can the prompt information in the input box be displayed and hidden according to the object gaining and losing focus. I am here today and want to share this little trick with you. I hope that all the masters will not make mistakes~~~

1. Requirements

Input input box, hide the prompt information when the cursor is displayed ; When the cursor leaves the input box, a prompt message is displayed.

2. Method

1. Give the input an id name, Onfocus="Method Name 1 (this)", onblur="Method Name 2 (this)"

2. Declare the variable value and obtain the input through the id name

3. Function method name 1 (inputObj){

Copy code The code is as follows:

if(inputObj.value==”…”){

inputObj.value=””;

}

}

4. function method name 2 (inputObj){
Copy code The code is as follows:

if(inputObj.value==””){

inputObj.value="…”;

}

}

5. Note: If there are multiple input tags on the same page that require the same settings, the method names cannot be consistent.

3. Example
Copy code The code is as follows:





Untitled document








Statement:
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