입력 URL 필수 속성은 입력 URL이 필수 설정 여부를 결정합니다.
구문
다음은 구문입니다 -
- 부울 값 반환 - true/false
inputURLObject.required
- 설정이 필수 booleanValue로
inputURLObject.required = booleanValue
부울 값
여기 "booleanValue" 다음과 같을 수 있습니다 -
| booleanValue | 세부정보 |
|---|---|
| 사실 | 양식을 제출하려면 url 필드를 설정해야 합니다. |
| 거짓 | 기본값이며 url 필드 설정은 필수가 아닙니다. |
예시
입력 URL 필수의 예를 살펴보겠습니다. 속성 -
<!DOCTYPE html>
<html>
<head>
<title>Input URL required</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-required</legend>
<label for="URLSelect">URL:
<input type="url" id="URLSelect" required>
</label><br>
<input type="button" onclick="showMessage()" value="Go">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
function showMessage() {
if(inputURL.required === true && inputURL.value === '')
divDisplay.textContent = 'Cannot Redirect: URL is Required';
else
divDisplay.textContent = 'Redirecting...';
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -
'이동' 클릭 버튼 -

'이동'을 클릭한 후 URL 필드 값이 설정된 버튼 -
