Latest web development tutorials

HTML DOM Input Date required 屬性

Input Date 對象參考手冊 Input Date對象

實例

查看date 字段在表單提交前是否是必填字段:

var x = document.getElementById("myDate").required;
x輸出結果為:
true

嘗試一下»

定義和用法

required 屬性用於設置或返回date 字段在表單提交前是否必填。

該屬性反映了HTML required 屬性。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持required 屬性,除了Safari瀏覽器和Internet Explorer 9 及更早IE版本瀏覽器。

注意: Internet Explorer或Firefox瀏覽器不支持<input type="date">元素。


語法

返回required 屬性:

dateObject .required

設置required 屬性:

dateObject .required=true|false

屬性值

描述
true|false 描述了 date 字段是否为表单中的必填字段。
  • true - date 字段为表单中必填字段
  • false - 默认。 date 字段不是表单中必填字段

技術細節

返回值: 布爾值,如果date 字段是表單中的必填字段返回true 否則返回false


更多實例

實例

設置date 字段為表單中的必填部分:

document.getElementById("myDate").required = true;

嘗試一下»


相關頁面

HTML參考手冊: HTML <input> required屬性


Input Date 對象參考手冊 Input Date對象