Input Datetime disabled attribute

Definition and Usage

disabled Attribute sets or returns whether the datetime field should be disabled.

Disabled elements are not available and cannot be clicked. By default, disabled elements are usually displayed in gray in the browser.

This property reflects the HTML disabled attribute.

See also:

HTML Reference Manual:HTML <input> disabled 属性

Example

Example 1

Disable the datetime field:

document.getElementById("myDatetime").disabled = true;

Try it yourself

Example 2

Check if the datetime field is disabled:

var x = document.getElementById("myDatetime").disabled;

Try it yourself

Example 3

Disable and enable the datetime field:

function disableBtn() {
    document.getElementById("myDatetime").disabled = true;
}
function undisableBtn() {
    document.getElementById("myDatetime").disabled = false;
}

Try it yourself

Syntax

Return disabled attribute:

datetimeObject.disabled

Set disabled attribute:

datetimeObject.disabled = true|false

Attribute value

Value Description
true|false

Specify whether the datetime field should be disabled.

  • true - The datetime field is disabled
  • false - Default. The datetime field is not disabled

Technical details

Return value: Boolean value, if the datetime field is disabled, it returns true,否则返回 false

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 10.0 支持 支持 支持

注意:<input type="datetime"> 元素在除 Safari 之外的任何主流浏览器中均不显示任何日期时间字段/日历。