Deselect contents of a textbox with javascript

后端 未结 8 1360
醉话见心
醉话见心 2020-12-10 13:47

I understand that with javascript you can select the contents of a textbox with the following code (in jQuery):

$(\"#txt1\").select();

Is t

相关标签:
8条回答
  • 2020-12-10 14:28

    what about this:

    $("input").focus(function(){
      this.selectionStart = this.selectionEnd = -1;
    });
    
    0 讨论(0)
  • 2020-12-10 14:29

    I'd like to suggest a simple solution

    $("input[type=text]").focus(function() {
        $(this).select();
    });
    
    $("input[type=text]").blur(function() {
        $('input[type="hidden"][value=""]').select();
    });
    
    //code....
    
    $("#txt1").focus();
    
    0 讨论(0)
提交回复
热议问题