คุณสมบัติ HTML DOM Input URL maxLength ส่งกลับ/ตั้งค่าคุณสมบัติ maxLength สำหรับ URL ที่ป้อน หากไม่ได้กำหนดคุณสมบัตินี้จะส่งคืน '-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> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิก 'เปลี่ยนความยาวสูงสุด' ปุ่ม −

หลังจากคลิก 'เปลี่ยนความยาวสูงสุด' ปุ่ม −

หลังจากคลิก 'เข้าสู่ระบบ' ปุ่มและการตั้งค่าการป้อนข้อมูลอีเมล -
