HTML DOM Textarea cols 屬性
HTML DOM Textarea cols 返回和修改 HTML 文件中文字區域元素的 cols 的屬性值。
語法
語法如下 −
1. 返回 cols
object.cols
2. 新增 cols
object.cols = “number”
我們來看看 HTML DOM Textarea cols 屬性的一個示例
示例
<!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>DOM Textarea cols Property Demo</h1> <textarea>Hi! I'm a textarea element in an HTML document with some dummy text.</textarea> <button onclick="set()" class="btn">Set Cols = 50</button> <script> function set() { document.querySelector("textarea").cols = '50'; } </script> </body> </html>
輸出
點選 “設定Cols = 50” 按鈕,將 cols 屬性的值設定為 50。
廣告