HTML DOM Input 郵箱名稱屬性
HTML DOM Input 郵箱名稱屬性返回一個 input 郵箱的 name 屬性值,使用者還可將屬性值設定為新的字串。
語法
語法如下 −
- 返回字串值
inputEmailObject.name
- 將name屬性設定為字串值
inputEmailObject.name = ‘String’
舉例
我們來看一個Input 郵箱 name屬性示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input Email name</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>
<fieldset>
<legend>Email-name</legend>
<label for="EmailSelect">Employee Email:
<input type="email" id="EmailSelect" value="x.agent@secret.com" name="Shasha-Miller">
</label>
<input type="button" onclick="getName()" value="Who's Email ID is this? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputEmail = document.getElementById("EmailSelect");
function getName() {
if(inputEmail.value === 'x.agent@secret.com')
divDisplay.textContent = 'Above Email belongs to '+inputEmail.name;
else
divDisplay.textContent = 'Above Email belongs to no one!';
}
</script>
</body>
</html>輸出
以下為輸出 −
點選“這是誰的電子郵件 ID?”按鈕之前 −

點選“這是誰的電子郵件 ID?”按鈕之後 −

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