Home > Web Front-end > JS Tutorial > JS method to select text in TextArea_javascript skills

JS method to select text in TextArea_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:47:46
Original
1263 people have browsed it

The example in this article describes the method of selecting text in TextArea using JS. Share it with everyone for your reference. The specific implementation method is as follows:

<script type="text/javascript">
  function select_field(id){
    document.getElementById(id).focus();
    document.getElementById(id).select();
  }
  function init(){
    select_field('text1');
  }
  onload=init;
</script>
<form>
This field gets selected onload:<br/>
<input type="text" name="text1" id="text1" value="some text" />
<br/>
<textarea name="textarea1" id="textarea1" rows="9" cols="50" wrap="off">Some long
content in here.
abcd efgh abcd efgh abcd efgh
abcd efgh abcd efgh abcd efgh
abcd efgh abcd efgh abcd efgh
</textarea>
<br/>
<input type="button" value="Select text" onclick="select_field('textarea1')">
</form>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template