HTML DOM Textarea cols 属性

htmldomweb developmentfront end technology更新于 2024/5/21 22:04:17

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>

输出

点击“Set Cols = 50”按钮将cols属性的值设置为50。


相关文章


有用资源