Textareacolsプロパティ_
例
テキスト領域の幅を変更します。
document.getElementById("myTextarea").cols = "100";
定義と使用法
colsプロパティは、テキスト領域のcols属性の値を設定または返します。
cols属性は、テキスト領域の表示幅を文字数で指定します。
ヒント: style.widthプロパティを使用して、テキスト領域の幅を設定することもできます。
ヒント:テキスト領域の高さを変更するには、rowsプロパティまたはstyle.heightプロパティを使用 します。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
cols | Yes | Yes | Yes | Yes | Yes |
構文
colsプロパティを返します。
textareaObject.cols
colsプロパティを設定します。
textareaObject.cols = number
プロパティ値
Value | Description |
---|---|
number | Specifies the width of the text area (in average character width). Default is 20 |
技術的な詳細
戻り値: | テキスト領域の幅を文字で表す数字 |
---|
その他の例
例
テキスト領域の幅を文字数で取得します。
var x = document.getElementById("myTextarea").cols;
例
style.widthプロパティを使用して、テキスト領域の幅を変更します。
document.getElementById("myTextarea").style.width = "500px";
例
colsプロパティとrowsプロパティを使用して、テキスト領域の幅と高さを変更します。
document.getElementById("myTextarea").cols = "100";
document.getElementById("myTextarea").rows = "10";
例
style.widthプロパティとstyle.heightプロパティを使用して、テキスト領域の幅と高さを変更します。
document.getElementById("myTextarea").style.width = "500px";
document.getElementById("myTextarea").style.height = "100px";
関連ページ
HTMLリファレンス:HTML <textarea> cols属性
❮Textareaオブジェクト