HTML入力値属性
HTML入力値属性は、値属性の値を設定/返すために使用されます。
入力値の例を見てみましょう プロパティ-
例
<!DOCTYPE html>
<html>
<head>
<title>Input URL value</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>URL-value</legend>
<label for="URLSelect">URL Id:
<input type="url" id="URLSelect">
<input type="button" onclick="getUserURL('google')" value="Google">
<input type="button" onclick="getUserURL('bing')" value="Bing"><br>
<input type="button" onclick="redirection()" value="Go">
</label>
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
function getUserURL(userName) {
if(userName === 'google')
inputURL.value = 'https://www.google.com';
else
inputURL.value = 'https://www.bing.com';
}
function redirection() {
if(inputURL.value !== '')
divDisplay.textContent = 'Redirecting to '+inputURL.value;
else
divDisplay.textContent = 'Enter URL';
}
</script>
</body>
</html> 出力
これにより、次の出力が生成されます-
1)[移動]をクリックします ’ボタンと空のURLフィールド-
2)[ Bing]をクリックした後 ’ボタン-
3)[移動]をクリックした後 URLフィールドが設定された’ボタン-
-
HTML値属性
HTML value属性は、HTMLドキュメント内のHTML要素の初期値を定義します。 ボタン、入力、メーター、li、オプション、進行状況に適用できます。 およびparam HTML要素。 構文 以下は構文です- <tagname value=”text”></tagname> HTML値の属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <style> body { color: #000; &n
-
HTMLmaxlength属性
HTML maxlength属性は、HTMLドキュメントの入力HTML要素で許可される最大文字数を定義します。 構文 以下は構文です- <input maxlength=”text”> HTMLmaxlength属性の例を見てみましょう- 例 <!DOCTYPE html> <html> <style> body { color: #000; height: 100vh;