


js operates input box prompt information and responds to mouse events_javascript skills
May 16, 2016 pm 04:54 PMWe 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:
<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:
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;
}
}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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?

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

Use JavaScript to implement custom styles and prompts for forms
