Textarea select()Method

Textarea 对象参考手册Textarea Object

Definition and Usage

The select() method is used to select the text in the element.

Syntax

textareaObject.select()


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the select() method


Example

Example

The following example can select the text in the text box:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult()
{
    document.getElementById("myTextarea").select();
}
</script>
</head>
<body>

<textarea id="myTextarea" cols="20">
At Example, you can learn a lot of basic programming knowledge, including HTML, XML, SQL, ASP, and PHP and various front-end content.
</textarea>
<br>

<button type="button" onclick="displayResult()">Select the text in the text box</button>

</body>
</html>



Textarea 对象参考手册Textarea Object Other Extensions