HTML DOM Input Email type 属性

htmlweb developmentfront end technology更新于 2025/7/29 9:48:17

HTML DOM Input Email type 属性返回/设置输入电子邮件的类型。

语法

以下是语法 −

  • 返回字符串值
inputEmailObject.type
  • 将 type 设置为字符串值
inputEmailObject.type = stringValue

字符串值

此处,“stringValue” 可以是以下 −

stringValue详细信息
email定义输入类型为 email
datetime-local定义输入类型为 datetime-local
radio定义输入类型为 radio
tel它定义了输入类型为电话,并显示数字键盘用于输入

示例

让我们看一个输入电子邮件类型属性的示例 −

<!DOCTYPE html>
<html>
<head>
<title>Input Email type</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-type</legend>
<label for="EmailSelect"></label>
<input type="email" id="EmailSelect" >
<input type="button" onclick="getTypeOfInput()" value="What to enter?">
</fieldset>
</form>
<script>
   var labelSelect = document.querySelector("label");
   var inputEmail = document.getElementById("EmailSelect");
   function getTypeOfInput() {
      labelSelect.innerHTML = inputEmail.type.toUpperCase()+' ID: ';
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"要输入什么?"按钮之前 −

点击"要输入什么?"按钮之后 −


相关文章


有用资源