HTMLDOMTextarea必須プロパティ
HTML DOM Textarea requiredプロパティは、HTMLドキュメントのテキスト領域のrequired属性の値を返し、変更します。
構文
以下は構文です-
1。返却が必要です
object.required
2。変更が必要です
object.required = true | false
HTML DOM Textarea requiredプロパティの例を見てみましょう:
例
<!DOCTYPE html>
<html>
<head>
<title>DOM Textarea required Property</title>
<style>
body {
text-align: center;
}
.btn {
display: block;
margin: 1rem auto;
background-color: #db133a;
color: #fff;
border: 1px solid #db133a;
padding: 0.5rem;
border-radius: 50px;
width: 20%;
}
.show-message {
font-weight: bold;
font-size: 1.4rem;
color: #ffc107;
}
</style>
</head>
<body>
<h1>DOM Textarea required Property Demo</h1>
<form id="form" method="post" action="">
<fieldset>
<legend>Form </legend>
<textarea rows="5" cols="20" required placeholder="Enter a message"></textarea>
<input type="submit" class="btn" value="Submit Form" onclick="checkRequired()">
</fieldset>
</form>
<div class="show-message"></div>
<script>
function checkRequired() {
var textarea = document.querySelector("textarea");
if (textarea.value === "") {
document.querySelector(".show-message").innerHTML = "Please enter a message!";
}
}
</script>
</body>
</html> 出力
「フォームを送信」をクリックします textarea要素にメッセージを入力せずに」ボタン。
-
HTML DOMTextareacolsプロパティ
HTML DOM Textarea colsは、HTMLドキュメントのテキスト領域要素のcols属性の値を返し、変更します。 構文 以下は構文です- 1。 colsを返す object.cols 2。列の追加 object.cols = “number” HTML DOM Textarea colsプロパティの例を見てみましょう: 例 <!DOCTYPE html> <html> <style> body { color: #000; &nb
-
HTML DOMTextareamaxLengthプロパティ
HTML DOM Textarea maxLengthプロパティは、HTMLドキュメントのテキスト領域要素のmaxLength属性の値を返し、変更します。 構文 以下は構文です- 1。 maxLengthを返す object.maxLength 2。 maxLengthの変更 object.maxLength = “number” HTML DOM Textarea maxLengthプロパティの例を見てみましょう: 例 <!DOCTYPE html> <html> <style> body {