jQuery - select all text from a textarea

后端 未结 6 2049
情书的邮戳
情书的邮戳 2020-11-27 12:03

How can I make it so when you click inside a textarea, its entire content gets selected?

And eventually when you click again, to deselect it.

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 12:39

    Selecting text in an element (akin to highlighting with your mouse)

    :)

    Using the accepted answer on that post, you can call the function like this:

    $(function() {
      $('#textareaId').click(function() {
        SelectText('#textareaId');
      });
    });
    

提交回复
热议问题