HTML DOM Textarea select() 方法
htmldomweb developmentfront end technology更新于 2024/5/21 23:08:17
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>
输出

点击"选择文本区域内容"按钮来选择文本区域元素的内容。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

