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。

更新时间: 2021 年 2 月 16 日

82 次浏览

启动你的 事业

完成课程获得认证

开始学习
广告
© . All rights reserved.