Deselect contents of a textbox with javascript

后端 未结 8 1392
醉话见心
醉话见心 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条回答
  •  Happy的楠姐
    2020-12-10 14:05

    Rather than selecting and then deselecting, why not just temporarily store a boolean on the dom element?

     $("input[type=text]").focus(function() {
         if($(this).skipFocus) return;
         $(this).select();
     });
    
     //code....
    
     $("#txt1").skipFocus = true;
     $("#txt1").focus();
    

提交回复
热议问题