คุณสมบัติ disabled ของ Textarea ใน HTML DOM ใช้สำหรับอ่านหรือตั้งค่าว่าเอลิเมนต์ textarea ในเอกสาร HTML ถูกปิดใช้งาน (disabled) หรือไม่
รูปแบบการใช้งาน (Syntax)
1. อ่านค่า disabled
object.disabled
2. ตั้งค่า disabled
object.disabled = true | false
ตัวอย่างการใช้งาน
<!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;
}
</style>
<body>
<h1>ตัวอย่างคุณสมบัติ disabled ของ Textarea</h1>
<textarea placeholder="Hi! I'm placeholder text of a textarea element" rows="8" cols='20'></textarea>
<button onclick="set()" class="btn">ปิดใช้งาน Textarea</button>
<script>
function set() {
document.querySelector("textarea").disabled = true;
}
</script>
</body>
</html>
ผลลัพธ์
คลิกที่ปุ่ม "ปิดใช้งาน Textarea" เพื่อปิดใช้งานเอลิเมนต์ textarea

