Select all text on focus using jQuery

后端 未结 3 888
谎友^
谎友^ 2021-01-07 19:52

I have a little jQuery function that is meant to automatically select text in an asp.net text box when it gets focus. However, the text in the text box gets selected, but im

3条回答
  •  爱一瞬间的悲伤
    2021-01-07 20:10

    It seems to be the mouseup event interfering. You'll notice if you click and hold in the form field then move outside of it to "mouseup" the selection sticks. Using mouseup instead of focus to trigger the select() method seems to work well:

    
    

    Demo: jsfiddle.net/gableroux/jvJzX/12

    See original demo for jQuery 1.3 - 1.8 compatible code.

提交回复
热议问题