คุณสมบัติ HTML DOM Textarea defaultValue ส่งกลับและแก้ไขค่าของแอตทริบิวต์ชื่อขององค์ประกอบพื้นที่ข้อความในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. ชื่อผู้ส่งคืน
object.name
2. การเพิ่มชื่อ
object.name = “text”
ให้เรามาดูตัวอย่าง HTML DOM Textarea name Property:
ตัวอย่าง
<!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 {
font-size: 1.5rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Textarea name Property Demo</h1>
<textarea rows="5" cols='20' name="I'm name attribute of textarea element">
Hi! I'm a textarea element with some dummy text.
</textarea>
<button onclick="set()" class="btn">Show Name Attribute Value</button>
<div class='show'></div>
<script>
function set() {
document.querySelector('.show').innerHTML = document.querySelector("textarea").name;
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “แสดงค่าแอตทริบิวต์ชื่อ ” เพื่อแสดงค่าแอตทริบิวต์ name ขององค์ประกอบ textarea
