jQuery clear input text on focus

前端 未结 3 1565
误落风尘
误落风尘 2021-02-20 06:06

I have this jQuery script:

$(document).ready(function() {
    $(\':input:enabled:visible:first\').focus();
    $(\'.letters\').keyup( function() {
          


        
相关标签:
3条回答
  • 2021-02-20 06:40

    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/

    0 讨论(0)
  • 2021-02-20 06:45

    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;
        }
      });
    });
    
    0 讨论(0)
  • 2021-02-20 06:49

    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.

    0 讨论(0)
提交回复
热议问题