📜  HTML | DOM 输入日期时间对象

📅  最后修改于: 2021-11-10 05:49:45             🧑  作者: Mango

HTML DOM 中的Input Datetime 对象用于表示 type=”datetime”的 HTML 输入元素。可以使用getElementById() 方法访问 type=”datetime”的输入元素。
句法:

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

输入日期时间对象属性:

Property Description
type This property is used to return which type of form element the Datetime field is.
value This property is used to set or return the value of the value attribute of a Datetime field.
autocomplete This property is used to set or return the value of the autocomplete attribute of a Datetime field.
autofocus This property is used to set or return the Datetime field get focus automatically when the page loads.
defaultValue This property is used to set or return the default value of a Datetime field.
disabled This property is used to set or return whether a Datetime field is disabled or not.
form This property is used to return reference to the form that contains the Datetime field.
list This property is used to return a reference to the datalist that contains the Datetime field.
max This property is used to set or return the value of the max attribute of a Datetime field.
min This property is used to set or return the value of the min attribute of a Datetime field.
name This property is used to set or return the value of the name attribute of a Datetime field.
placeholder This property is used to set or return the value of the placeholder attribute of a Datetime field.
readOnly This property is used to set or return whether the Datetime field is read-only or not.
required This property is used to set or return whether the Datetime field must be filled out before submitting a form.
step This property is used to set or return the value of the step attribute of a Datetime field.

输入日期时间对象方法:

Method Description
stepDown() This method is used to decrement the value of the input Datetime by a specified number.
stepUp() This method is used to increment the value of the input Datetime by a specified number.

示例 1:使用“document.getElementById(“id”);”返回日期时间.



  

  
    
  
        

                GeeksForGeeks            

           

DOM Input Datetime Object

                       

Click the button to get the date and time of the datetime field.

                       

                      

输出:

点击按钮前:

点击按钮后:

示例 2:创建“datetime”元素



  

  
    

                GeeksForGeeks            

       

DOM Input Datetime Object

       

      Click the button to create a Datetime field.   

                     

输出:

点击按钮前:

点击按钮后:

支持的浏览器:

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