HTMLDOM入力URL値プロパティ
値属性が入力URLに定義されている場合、HTMLDOM入力URL値プロパティは文字列を返します。ユーザーはそれを新しい文字列に設定することもできます。
構文
以下は構文です-
- 文字列値を返す
inputURLObject.value
- 値属性を文字列値に設定する
inputURLObject.value = ‘String’
例
入力URL値の例を見てみましょう プロパティ-
<!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> 出力
これにより、次の出力が生成されます-
「実行」をクリックします 空のURLフィールドのあるボタン-
「Bing」をクリックした後 ボタン-
[実行]をクリックした後 URLフィールドが設定されたボタン-
-
HTMLDOM入力URLプレースホルダープロパティ
HTML DOM入力URLプレースホルダープロパティは、入力テキストがどのように表示されるかについてユーザーにヒントを与えるために一般的に使用される文字列を設定/返します。 構文 以下は構文です- 文字列値を返す inputURLObject.placeholder プレースホルダーの設定 stringValueへ inputURLObject.placeholder = stringValue 例 入力URLプレースホルダープロパティの例を見てみましょう- <!DOCTYPE html> <html> <head> <title>I
-
HTMLDOM入力URLパターンプロパティ
HTML DOM入力URLパターンプロパティは、URL入力に対応する正規表現を設定/返します。パターン属性の値は、URLフィールドに入力されたテキストと照合されます。 Sytax 以下は構文です- 正規表現を返す inputURLObject.pattern パターンの設定 正規表現へ inputURLObject.pattern = ‘RegExp’ 例 入力URLパターンの例を見てみましょう プロパティ- <!DOCTYPE html> <html> <head> <title>Input URL pa