📜  HTML | DOM 输入文本对象

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

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

句法:

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

输入文本对象属性:

Property Description
type It is used to return the type of form element to the text field.
value This property is used to set or return the value of the value attribute of the text field.
autocomplete This property is used to set or return the value of the autocomplete attribute of a text field.
autofocus This property is used to set or return whether a text field should automatically get focus when the page loads.
defaultValue This property is used to set or return the default value of a text field.
disabled This property is used to set or return whether a text field is disabled or not.
form This property is used to return reference to the form that contains the text field.
list This property is used to return a reference to the datalist that contains the text field.
maxLength This property is used to set or return the value of the maxlength attribute of a text field.
name This property is used to set or return the value of the name attribute of a text field.
pattern This property is used to set or return the value of the pattern attribute of a text field.
placeholder This property is used to set or return the value of the placeholder attribute of a text field.
readOnly This property is used to set or return whether the text field is read-only or not.
required This property is used to set or return whether the text 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 text field.

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

html


 

    
        HTML DOM Input Text Object
    
  
 

 
    

GeeksForGeeks

      

DOM Input Text Object

                  

Click on button to display the text field

                       

                   


html


 

    
        HTML DOM Input Text Object
    
  
 

 
    

GeeksForGeeks

      

DOM Input Text Object

       

Click the button to create Text Field

                              


输出:
点击按钮前:

点击按钮后:

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

html



 

    
        HTML DOM Input Text Object
    
  
 

 
    

GeeksForGeeks

      

DOM Input Text Object

       

Click the button to create Text Field

                                                  

输出:
点击按钮前:

点击按钮后:

支持的浏览器:

  • 谷歌浏览器
  • 边缘
  • 火狐浏览器
  • 歌剧
  • 苹果浏览器