Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML DOM 입력 URL maxLength 속성

<시간/>

HTML DOM 입력 URL maxLength 속성은 입력 URL에 대한 maxLength 속성을 반환/설정합니다. 정의되지 않은 경우 이 속성은 '-1'을 반환합니다.

구문

다음은 구문입니다 -

  • maxLength 속성 반환
inputURLObject.maxLength
  • maxLength 속성을 숫자로 설정
inputURLObject.maxLength = number

예시

입력 URL maxLength 속성의 예를 살펴보겠습니다 -

<!DOCTYPE html>
<html>
<head>
<title>Input URL maxLength</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 id="Google">
<fieldset>
<legend>URL-maxLength</legend>
<label for="URLSelect">URL :
<input type="url" id="URLSelect" maxLength="10">
</label>
<input type="button" onclick="logIN()" value="Log In">
<input type="button" onclick="changeMaxLength()" value="Change Maxlength">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputURL = document.getElementById("URLSelect");
   divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   function changeMaxLength() {
      inputURL.maxLength += 10;
      divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   }
   function logIN(){
      if(inputURL.value !== '')
         divDisplay.textContent = 'Could not identify url, Redirecting to '+inputURL.form.id;
   }
</script>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

'최대 길이 변경'을 클릭하기 전에 버튼 -

HTML DOM 입력 URL maxLength 속성

'최대 길이 변경'을 클릭한 후 버튼 -

HTML DOM 입력 URL maxLength 속성

'로그인'을 클릭한 후 버튼 및 이메일 입력 설정 -

HTML DOM 입력 URL maxLength 속성