Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:54:40
Original
1143 people have browsed it

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:



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;
}
}
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template