Js operation input box prompts and responds to mouse events

  • 2020-03-30 02:26:48
  • OfStack

We often encounter some input box, such as the registration of the site's input box has a default prompt value, when the mouse focus, the default value is deleted, when the user did not enter something to leave the focus, and restore the default prompt value. This method is implemented in js code as follows:

HTML code:
<input type="text" id="email" name="email" class="txt_input" value=" Please enter your frequently used mailbox " 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; 

Related articles: