jQuery clear input text on focus

风流意气都作罢 提交于 2019-12-04 02:23:58

To filter the input, use

​$('input').on('keydown', function(e) {
    if( !/[a-z]|[A-Z]/.test( String.fromCharCode( e.which ) ) )
        return false;
});​​​​​​​​

To clear the input field on click & focus, use

$('input').on('click focusin', function() {
    this.value = '';
});

Be aware of that this event will fire twice, when you click into a non-focused input control in its current form.

Demo: http://jsfiddle.net/xbeR2/

Jason Towne

To answer your focus question, yes you can do that:

$("input").focus(function() {
  this.value = "";
});

To answer the only allow letters question, this has been asked before.

use this

$( document ).ready(function() {
  var search_text_s = "WYSZUKAJ";

  // author ZMORA
  // search input focus text
  $("#searchClear").focus(function() {
    if(this.value == search_text_s){
      this.value = "";
    }
  }).blur(function() {
    if(this.value != search_text_s){
      this.value = search_text_s;
    }
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!