Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

แอตทริบิวต์ readOnly ใน HTML

แอตทริบิวต์ readOnly ใน HTML แสดงว่าองค์ประกอบ input/textarea เป็นแบบอ่านอย่างเดียว (read-only) หมายความว่าคุณไม่สามารถแก้ไขเนื้อหาของมันได้ในเอกสาร HTML

ไวยากรณ์

<tagname readOnly></tagname>

ตัวอย่าง

<!DOCTYPE html>
<html>
<style>
  body {
    color: #000;
    height: 100vh;
    background-color: #8BC6EC;
    background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
    text-align: center;
  }
  input {
    display: block;
    width: 50%;
    margin: 1rem auto;
    text-align: center;
  }
</style>
<body>
<h1>ตัวอย่าง HTML readOnly</h1>
<input type="text" value="ฉันคือองค์ประกอบ input ที่มีคุณสมบัติ readOnly" readOnly>
</body>
</html>

ผลลัพธ์

แสดงช่องป้อนข้อความที่ไม่สามารถแก้ไขได้ มีข้อความ "ฉันคือองค์ประกอบ input ที่มีคุณสมบัติ readOnly"