HTML DOM 輸入電子郵件 maxLength 屬性
HTML DOM 輸入電子郵件 maxLength 屬性返回/設定輸入電子郵件的 maxLength 屬性。如果未定義此屬性,則返回“-1”。
語法
以下是語法 -
- 返回maxLength屬性
inputEmailObject.maxLength
- 將maxLength屬性設定為數字
inputEmailObject.maxLength = number
示例
讓我們看一個輸入電子郵件 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>輸出
將產生以下輸出 -
在點選“更改最大長度”按鈕之前 -

在點選“更改最大長度”按鈕之後 -

在點選“登入”按鈕並設定電子郵件輸入之後 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP