HTML DOM Input Email name 属性
htmlweb developmentfront end technology更新于 2025/6/28 1:16:17
HTML DOM 输入电子邮件 name 属性返回 a,即输入电子邮件 name 属性的值。用户也可以将其设置为新的字符串。
语法
以下是语法 −
- 返回字符串值
inputEmailObject.name
- 将 name 属性设置为字符串值
inputEmailObject.name = ‘String’
示例
让我们看一个 Input Email 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?"按钮之后 −

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

