HTML DOM 입력 URL 값 속성은 값 속성이 입력 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 필드가 설정된 버튼 -
