📜  HTML | DOM 输入电子邮件对象

📅  最后修改于: 2021-10-31 05:07:04             🧑  作者: Mango

HTML DOM 中的Input Email Object用于表示具有 type=”email”属性的 HTML input 元素。可以使用 getElementById() 方法访问具有 type=”email”属性的输入元素。

句法:

  • 它用于访问输入电子邮件对象。
document.getElementById("id");
  • 它用于创建输入元素。
document.createElement("input");

输入电子邮件对象属性:

Property Description
type This property is used to return the type of form element to the email field.
value This property is used to set or return the value of the value attribute of an email field.
autocomplete This property is used to set or return the value of the autocomplete attribute of an email field.
autofocus This property is used to set or return whether an email field should automatically get focus when the page loads.
defaultValue This property is used to set or return the default value of an email field.
disabled This property is used to set or return whether an email field is disabled or not.
form This property is used to return reference to the form that contains the email field.
list This property is used to return a reference to the datalist that contains the email field.
maxLength This property is used to set or return the value of the maxlength attribute of an email field.
multiple This property is used to set or return whether a user is allowed to enter more than one email address in the email field.
name This property is used to set or return the value of the name attribute of an email field.
pattern This property is used to set or return the value of the pattern attribute of an email field.
placeholder This property is used to set or return the value of the placeholder attribute of an email field.
readOnly This property is used to set or return whether the email field is read-only or not.
required This property is used to set or return whether the email field must be filled out before submitting a form.
size This property is used to set or return the value of the size attribute of the email field.

示例 1:此示例使用 getElementById() 方法访问具有 type=”email” 属性的 元素。

html


     

    
        HTML DOM Input Email Object
    
   
 

 
    

GeeksforGeeks

      

DOM Input Email Object

      E-mail:                  

                   


html


     

    
        HTML DOM Input Email Object
    
   
 

 
    

GeeksforGeeks

      

DOM Input Email Object

                        


输出:
点击按钮前:

点击按钮后:

示例 2:此示例使用 document.createElement() 方法创建具有 type=”email” 属性的 元素。

html



     

    
        HTML DOM Input Email Object
    
   
 

 
    

GeeksforGeeks

      

DOM Input Email Object

                                            

输出:
点击按钮前:

点击按钮后:

支持的浏览器

  • 谷歌浏览器
  • Internet Explorer(IE 9 之后)
  • 火狐
  • 歌剧