HTML DOM Textarea select() วิธีการเลือกเนื้อหาของพื้นที่ข้อความในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
object.select()
ให้เราดูตัวอย่างของ HTML DOM Textarea select() Method -
ตัวอย่าง
<!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
