คุณสมบัติตัวยึดตำแหน่ง HTML DOM Textarea ส่งกลับและแก้ไขค่าของแอตทริบิวต์ตัวยึดตำแหน่งขององค์ประกอบพื้นที่ข้อความในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. ส่งคืนตัวยึดตำแหน่ง
object.placeholder
2. การเพิ่มตัวยึดตำแหน่ง
object.placeholder = “text”
ให้เราดูตัวอย่างของคุณสมบัติตัวยึดตำแหน่ง HTML DOM Textarea:
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
background: lightseagreen;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
.show {
margin: 1rem 0;
font-size: 1.5rem;
}
</style>
<body>
<h1>DOM Textarea placeholder Property Demo</h1>
<textarea placeholder="Hi! I'm placeholder text of a textarea element" rows="8" cols='20'></textarea>
<button onclick="set()" class="btn">Show Placeholder</button>
<div class="show"></div>
<script>
function set() {
document.querySelector('.show').innerHTML = document.querySelector("textarea").placeholder;
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “แสดงตัวยึดตำแหน่ง ” เพื่อแสดงค่าของแอตทริบิวต์ตัวยึดตำแหน่ง
