select()
Textarea select() 方法
定义和用法
select() 方法用于选择该元素中的文本。
语法
textareaObject.select()
浏览器支持
所有主流浏览器都支持 select() 方法
实例
下面的例子可选择文本框中的文本:
<html>
<head>
<script>
function displayResult()
{
document.getElementById("myTextarea").select();
}
</script>
</head>
<body>
<textarea id="myTextarea" cols="20">
At bubufx you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP.
</textarea>
<br>
<button type="button" onclick="displayResult()">Select contents of text area</button>
</body>
</html>
<head>
<script>
function displayResult()
{
document.getElementById("myTextarea").select();
}
</script>
</head>
<body>
<textarea id="myTextarea" cols="20">
At bubufx you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP.
</textarea>
<br>
<button type="button" onclick="displayResult()">Select contents of text area</button>
</body>
</html>