HTML DOM Input Email maxLength 属性
htmlweb developmentfront end technology更新于 2025/6/26 4:28:17
HTML DOM Input Email maxLength 属性返回/设置输入电子邮件的 maxLength 属性。如果未定义,此属性返回"-1"。
语法
以下是语法 −
- 返回 maxLength 属性
inputEmailObject.maxLength
- 将 maxLength 属性设置为 number
inputEmailObject.maxLength = number
示例
让我们看一个 Input Email maxLength 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input Email 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="Multitech-MNC">
<fieldset>
<legend>Email-maxLength</legend>
<label for="EmailSelect">Employee Email :
<input type="email" id="EmailSelect" placeholder="jkl@qwerty.com" 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 inputEmail = document.getElementById("EmailSelect");
divDisplay.textContent = 'Maxlength: '+inputEmail.maxLength;
function changeMaxLength() {
inputEmail.maxLength += 5;
divDisplay.textContent = 'Maxlength: '+inputEmail.maxLength;
}
function logIN(){
if(inputEmail.value !== '')
divDisplay.textContent = 'Logging Into: '+inputEmail.form.id;
else
divDisplay.textContent = 'Please enter valid email';
}
</script>
</body>
</html>
输出
这将产生以下输出 −
点击"更改最大长度"按钮之前 −

点击"更改最大长度"按钮之后 −

点击"登录"按钮并设置邮箱地址后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

