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

คุณสมบัติ cols ของ Textarea ใน HTML DOM


คุณสมบัติ cols ของ Textarea ใน HTML DOM ใช้สำหรับอ่านหรือตั้งค่าของแอตทริบิวต์ cols ของเอลิเมนต์ textarea ในเอกสาร HTML

รูปแบบการใช้งาน (Syntax)

1. อ่านค่า cols

object.cols

2. ตั้งค่า cols

object.cols = "number"

ตัวอย่างการใช้งาน

<!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>ตัวอย่างคุณสมบัติ cols ของ Textarea</h1>
<textarea>Hi! I'm a textarea element in an HTML document with some dummy text.</textarea>
<button onclick="set()" class="btn">ตั้งค่า Cols = 50</button>
<script>
  function set() {
    document.querySelector("textarea").cols = '50';
  }
</script>
</body>
</html>

ผลลัพธ์

คลิกที่ปุ่ม "ตั้งค่า Cols = 50" เพื่อตั้งค่าของแอตทริบิวต์ cols เป็น 50

คุณสมบัติ cols ของ Textarea ใน HTML DOM

คุณสมบัติ cols ของ Textarea ใน HTML DOM