Home Web Front-end JS Tutorial js operates input box prompt information and responds to mouse events_javascript skills

js operates input box prompt information and responds to mouse events_javascript skills

May 16, 2016 pm 04:54 PM
Prompt message Input box

We often encounter some input boxes. For example, the input box for a registration website has a default prompt value. When the mouse focus is obtained, the default value is deleted. When the user leaves the focus without inputting anything, the default prompt value is restored. This method is implemented with js code as follows:

html code:

Copy code The code is as follows:

<input type="text" id="email" name="email" class="txt_input" value="Please enter your frequently used email address" onfocus="fn_focus(this);" onblur=" fn_blur(this);"/>

js code:
Copy code The code is as follows:

function fn_focus(ele){
if(ele.value == ele.defaultValue){
ele.value = '';
}
}
function fn_blur(ele){
var reg = /^[s]*$/;
if(reg.test(ele.value) || ele.value == ele.defaultValue){
ele.value = ele.defaultValue;
}
}
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to let all users print specified prompt information when logging in in Linux How to let all users print specified prompt information when logging in in Linux Feb 19, 2024 pm 05:12 PM

How to let all users print specified prompt information when logging in in Linux

Tips and tutorials for solving win11 installation issues Tips and tutorials for solving win11 installation issues Jan 09, 2024 pm 07:10 PM

Tips and tutorials for solving win11 installation issues

Use jQuery to implement an input box that only allows numbers and decimal points to be entered Use jQuery to implement an input box that only allows numbers and decimal points to be entered Feb 26, 2024 am 11:21 AM

Use jQuery to implement an input box that only allows numbers and decimal points to be entered

Teach you step by step how to use CSS to create a simple and elegant input box Teach you step by step how to use CSS to create a simple and elegant input box Jan 13, 2023 pm 03:55 PM

Teach you step by step how to use CSS to create a simple and elegant input box

What is the optimization method for input box length limit in Vue development? What is the optimization method for input box length limit in Vue development? Jun 30, 2023 am 08:44 AM

What is the optimization method for input box length limit in Vue development?

How to implement a labeled input box using Vue? How to implement a labeled input box using Vue? Jun 25, 2023 am 11:54 AM

How to implement a labeled input box using Vue?

Implement the required requirements for the name input box when the HTML page jumps to the PHP page Implement the required requirements for the name input box when the HTML page jumps to the PHP page Mar 10, 2024 am 10:21 AM

Implement the required requirements for the name input box when the HTML page jumps to the PHP page

Use JavaScript to implement custom styles and prompts for forms Use JavaScript to implement custom styles and prompts for forms Jun 15, 2023 pm 02:41 PM

Use JavaScript to implement custom styles and prompts for forms

See all articles