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

WBOY
WBOYOriginal
2016-05-16 16:54:401164browse

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;
}
}
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