HTML DOM Input URL maxLength 属性
htmlweb developmentfront end technology更新于 2025/6/15 19:56:17
HTML DOM Input URL maxLength 属性返回/设置输入 URL 的 maxLength 属性。如果未定义,此属性返回"-1"。
语法
以下是语法 −
- 返回 maxLength 属性
inputURLObject.maxLength
- 将 maxLength 属性设置为数字
inputURLObject.maxLength = 数字
示例
让我们看一个 Input 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 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

