jQuery-添加/聚焦/模糊输入值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery-添加/聚焦/模糊输入值相关的知识,希望对你有一定的参考价值。

First value takes empty input values and adds 'Enter Value'.
Second snippet removes 'Enter Value' when input is focused.
Third snippet re-adds 'Enter Value' if the value is left blank.
  1. $(function(){
  2.  
  3. $('input[type="text"]').each(function(){
  4. if(this.value==''){this.value='Enter Value'}
  5. });
  6.  
  7. $('input[type="text"]').focus(function(){
  8. if(this.value=='Enter Value'){this.value=''}
  9. });
  10.  
  11. $('input[type="text"]').blur(function(){
  12. if(this.value==''){this.value='Enter Value'}
  13. });
  14.  
  15. });

以上是关于jQuery-添加/聚焦/模糊输入值的主要内容,如果未能解决你的问题,请参考以下文章