跳到內容
欄目
Fiesta

field-datetime

日期同時間 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-datetime_live">發佈日期</label>
  <input rst-input id="field-datetime_live" name="field-datetime_live" type="datetime-local" value="2026-09-04T19:30" aria-describedby="field-datetime_live-hint" data-rst-date data-rst-date-words="{&#34;ago&#34;:&#34;前|之前&#34;,&#34;am&#34;:&#34;上午|朝早|am&#34;,&#34;at&#34;:&#34;喺&#34;,&#34;day&#34;:&#34;日|天|號|号&#34;,&#34;hour&#34;:&#34;鐘|個鐘|小時|點&#34;,&#34;in&#34;:&#34;後|之後&#34;,&#34;last&#34;:&#34;上|上個&#34;,&#34;midnight&#34;:&#34;午夜|半夜&#34;,&#34;minute&#34;:&#34;分鐘|分&#34;,&#34;month&#34;:&#34;月|個月&#34;,&#34;next&#34;:&#34;下|下個&#34;,&#34;noon&#34;:&#34;中午|晏晝&#34;,&#34;pm&#34;:&#34;下午|夜晚|pm&#34;,&#34;today&#34;:&#34;今日&#34;,&#34;tomorrow&#34;:&#34;聽日|明日&#34;,&#34;week&#34;:&#34;星期|禮拜|週&#34;,&#34;yesterday&#34;:&#34;尋日|琴日|昨日&#34;}" 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-datetime_live-hint">幾時上線。</small>
</div>

必填,仲有錯誤

預覽

將呢段放入 <section rst-box><form rst-form> 入面。

<div rst-field>
  <label rst-field-label for="field-datetime_error">發佈日期 <span rst-field-required aria-hidden="true">*</span></label>
  <input rst-input id="field-datetime_error" name="field-datetime_error" type="datetime-local" required aria-invalid="true" aria-describedby="field-datetime_error-error" data-rst-date data-rst-date-words="{&#34;ago&#34;:&#34;前|之前&#34;,&#34;am&#34;:&#34;上午|朝早|am&#34;,&#34;at&#34;:&#34;喺&#34;,&#34;day&#34;:&#34;日|天|號|号&#34;,&#34;hour&#34;:&#34;鐘|個鐘|小時|點&#34;,&#34;in&#34;:&#34;後|之後&#34;,&#34;last&#34;:&#34;上|上個&#34;,&#34;midnight&#34;:&#34;午夜|半夜&#34;,&#34;minute&#34;:&#34;分鐘|分&#34;,&#34;month&#34;:&#34;月|個月&#34;,&#34;next&#34;:&#34;下|下個&#34;,&#34;noon&#34;:&#34;中午|晏晝&#34;,&#34;pm&#34;:&#34;下午|夜晚|pm&#34;,&#34;today&#34;:&#34;今日&#34;,&#34;tomorrow&#34;:&#34;聽日|明日&#34;,&#34;week&#34;:&#34;星期|禮拜|週&#34;,&#34;yesterday&#34;:&#34;尋日|琴日|昨日&#34;}" 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-datetime_error-error">揀一個今日之後嘅日子。</small>
</div>

有上下限

預覽

將呢段放入 <section rst-box><form rst-form> 入面。

<div rst-field>
  <label rst-field-label for="field-datetime_bounded">今年之內</label>
  <input rst-input id="field-datetime_bounded" name="field-datetime_bounded" type="datetime-local" value="2026-09-04T19:30" min="2026-01-01T00:00" max="2026-12-31T23:59" data-rst-date data-rst-date-words="{&#34;ago&#34;:&#34;前|之前&#34;,&#34;am&#34;:&#34;上午|朝早|am&#34;,&#34;at&#34;:&#34;喺&#34;,&#34;day&#34;:&#34;日|天|號|号&#34;,&#34;hour&#34;:&#34;鐘|個鐘|小時|點&#34;,&#34;in&#34;:&#34;後|之後&#34;,&#34;last&#34;:&#34;上|上個&#34;,&#34;midnight&#34;:&#34;午夜|半夜&#34;,&#34;minute&#34;:&#34;分鐘|分&#34;,&#34;month&#34;:&#34;月|個月&#34;,&#34;next&#34;:&#34;下|下個&#34;,&#34;noon&#34;:&#34;中午|晏晝&#34;,&#34;pm&#34;:&#34;下午|夜晚|pm&#34;,&#34;today&#34;:&#34;今日&#34;,&#34;tomorrow&#34;:&#34;聽日|明日&#34;,&#34;week&#34;:&#34;星期|禮拜|週&#34;,&#34;yesterday&#34;:&#34;尋日|琴日|昨日&#34;}" 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-datetime_plain">發佈日期</label>
  <input rst-input id="field-datetime_plain" name="field-datetime_plain" type="datetime-local" value="2026-09-04T19:30">
</div>