HTML DOM Textarea select() 方法
HTML DOM Textarea select() 方法选中 HTML 文档中的文本区域内容。
语法
以下为语法 −
object.select()
让我们看一个 HTML DOM Textarea select() 方法示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
<body>
<h1>DOM Textarea select() Method Demo</h1>
<textarea rows='5' cols="30">Hi! I'm a text area element with some dummy text.</textarea>
<button onclick="set()" class="btn">Select textarea content</button>
<script>
function set() {
document.querySelector("textarea").select();
}
</script>
</body>
</html>输出

单击“选择 textarea 内容”按钮以选择 textarea 元素的内容。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP