field-date
日期同時間 datetime.js 加強嘅四個欄位,每個下面都保留原生輸入元件,所以冇腳本嘅讀者見到嘅係樸素嘅控件,唔係壞咗嘅。
原生日期輸入框,加上輸入框有 data-rst-date 嗰陣 datetime.js 加上去嘅自然語言組合框。試吓打 「聽日」 入去。
每個例子都真係用得,不過入面啲連結唔會帶你去邊度。 HTML 顯示可以複製嘅標記。
增強輸入:打「聽日」或者「3 個星期後」
佢識解嘅字喺 data-rst-date-words 度,呢度係用緊頁面嘅語言。i18n/<lang>.json 有十二種語言嘅版本,所以無論頁面用緊邊種語言,個欄位都解得到。
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="field-date_live" >發佈日期</label >
<input rst-input id ="field-date_live" name ="field-date_live" type ="date" value ="2026-09-04" aria-describedby ="field-date_live-hint" data-rst-date data-rst-date-words ="{"ago":"前|之前","am":"上午|朝早|am","at":"喺","day":"日|天|號|号","hour":"鐘|個鐘|小時|點","in":"後|之後","last":"上|上個","midnight":"午夜|半夜","minute":"分鐘|分","month":"月|個月","next":"下|下個","noon":"中午|晏晝","pm":"下午|夜晚|pm","today":"今日","tomorrow":"聽日|明日","week":"星期|禮拜|週","yesterday":"尋日|琴日|昨日"}" data-rst-date-set ="設定" data-rst-date-hint ="試下:{example}" data-rst-date-pick ="打開日曆" data-rst-date-calendar ="日曆" data-rst-date-prev-month ="上個月" data-rst-date-next-month ="下個月" data-rst-date-results ="{n} 個建議" data-rst-date-result-one ="1 個建議" data-rst-date-quick-today ="今日" data-rst-date-quick-tomorrow ="聽日" data-rst-date-quick-next-week ="一個星期之後" data-rst-date-quick-plus-1h ="一個鐘之後" data-rst-date-quick-plus-2h ="兩個鐘之後" data-rst-date-quick-end-of-day ="嗰日結束" data-rst-date-quick-next-day ="第二日同一個時間" >
<small rst-field-hint id ="field-date_live-hint" >上線嗰日。</small >
</div >
必填,仲有錯誤
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="field-date_error" >發佈日期 <span rst-field-required aria-hidden ="true" >*</span ></label >
<input rst-input id ="field-date_error" name ="field-date_error" type ="date" required aria-invalid ="true" aria-describedby ="field-date_error-error" data-rst-date data-rst-date-words ="{"ago":"前|之前","am":"上午|朝早|am","at":"喺","day":"日|天|號|号","hour":"鐘|個鐘|小時|點","in":"後|之後","last":"上|上個","midnight":"午夜|半夜","minute":"分鐘|分","month":"月|個月","next":"下|下個","noon":"中午|晏晝","pm":"下午|夜晚|pm","today":"今日","tomorrow":"聽日|明日","week":"星期|禮拜|週","yesterday":"尋日|琴日|昨日"}" data-rst-date-set ="設定" data-rst-date-hint ="試下:{example}" data-rst-date-pick ="打開日曆" data-rst-date-calendar ="日曆" data-rst-date-prev-month ="上個月" data-rst-date-next-month ="下個月" data-rst-date-results ="{n} 個建議" data-rst-date-result-one ="1 個建議" data-rst-date-quick-today ="今日" data-rst-date-quick-tomorrow ="聽日" data-rst-date-quick-next-week ="一個星期之後" data-rst-date-quick-plus-1h ="一個鐘之後" data-rst-date-quick-plus-2h ="兩個鐘之後" data-rst-date-quick-end-of-day ="嗰日結束" data-rst-date-quick-next-day ="第二日同一個時間" >
<small rst-field-error id ="field-date_error-error" >揀一個今日之後嘅日子。</small >
</div >
有上下限
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="field-date_bounded" >今年之內</label >
<input rst-input id ="field-date_bounded" name ="field-date_bounded" type ="date" value ="2026-09-04" min ="2026-01-01" max ="2026-12-31" data-rst-date data-rst-date-words ="{"ago":"前|之前","am":"上午|朝早|am","at":"喺","day":"日|天|號|号","hour":"鐘|個鐘|小時|點","in":"後|之後","last":"上|上個","midnight":"午夜|半夜","minute":"分鐘|分","month":"月|個月","next":"下|下個","noon":"中午|晏晝","pm":"下午|夜晚|pm","today":"今日","tomorrow":"聽日|明日","week":"星期|禮拜|週","yesterday":"尋日|琴日|昨日"}" data-rst-date-set ="設定" data-rst-date-hint ="試下:{example}" data-rst-date-pick ="打開日曆" data-rst-date-calendar ="日曆" data-rst-date-prev-month ="上個月" data-rst-date-next-month ="下個月" data-rst-date-results ="{n} 個建議" data-rst-date-result-one ="1 個建議" data-rst-date-quick-today ="今日" data-rst-date-quick-tomorrow ="聽日" data-rst-date-quick-next-week ="一個星期之後" data-rst-date-quick-plus-1h ="一個鐘之後" data-rst-date-quick-plus-2h ="兩個鐘之後" data-rst-date-quick-end-of-day ="嗰日結束" data-rst-date-quick-next-day ="第二日同一個時間" >
</div >
Plain:冇加嘢嘅原生輸入框
完全冇加強用嘅屬性,所以 datetime.js 搵唔到嘢。原生揀選器照樣開得到。
將呢段放入 <section rst-box><form rst-form> 入面。
<div rst-field >
<label rst-field-label for ="field-date_plain" >發佈日期</label >
<input rst-input id ="field-date_plain" name ="field-date_plain" type ="date" value ="2026-09-04" >
</div >