HTML DOM 输入 URL maxLength 属性
HTML DOM Input URL maxLength 属性返回/设置输入 URL 的 maxLength 属性。如果未定义,该属性返回“ -1”。
语法
以下是语法 −
- 返回 maxLength 属性
inputURLObject.maxLength
- 设置 maxLength 属性为一个数字
inputURLObject.maxLength = number
示例
让我们看一个使用 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>输出
将产生以下输出 −
在单击“更改最大长度”按钮之前 −

在单击“更改最大长度”按钮之后 −

在单击“登录”按钮并设置电子邮件输入 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP