Thuộc tính maxLength URL đầu vào HTML DOM trả về / đặt thuộc tính maxLength cho URL đầu vào. Nếu không được xác định, thuộc tính này trả về ‘-1’.
Cú pháp
Sau đây là cú pháp -
- Trả về thuộc tính maxLength
inputURLObject.maxLength
- Đặt thuộc tính maxLength thành một số
inputURLObject.maxLength = number
Ví dụ
Hãy để chúng tôi xem một ví dụ về thuộc tính URL đầu vào 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> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Trước khi nhấp vào ‘Thay đổi Maxlength’ nút -
Sau khi nhấp vào ‘Thay đổi Maxlength’ nút -
Sau khi nhấp vào ‘Đăng nhập’ nút và cài đặt đầu vào email -