跳到内容
栏目
Fiesta

field-daterange

日期与时间 datetime.js 增强的四个字段,每个都在底层保留原生输入控件,因此没有脚本的读者得到的是朴素的控件,而不是坏掉的控件。

起点和终点作为一个带标签的 fieldset。给每个输入框各自的 name 和 id。

每个示例都能真实操作,但其中的链接不会跳转到任何地方。 HTML 显示可复制的标记。

日期和时间,已预填

在结束时间还空着的时候确定开始时间,datetime.js 会把结束填成一小时之后。标记里没有任何东西做这件事,是脚本做的。

预览

把这段放进 <section rst-box><form rst-form> 里。

<fieldset rst-field-range>
  <legend>时间</legend>
  <div rst-field-row data-rst-range="session">
    <div rst-field>
      <label rst-field-label for="dr_starts_at">开始</label>
      <input rst-input id="dr_starts_at" name="dr_starts_at" type="datetime-local" value="2026-09-04T19:30" 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>
    <div rst-field>
      <label rst-field-label for="dr_ends_at">结束</label>
      <input rst-input id="dr_ends_at" name="dr_ends_at" type="datetime-local" 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>
  </div>
</fieldset>

只有日期,结束一侧带错误

预览

把这段放进 <section rst-box><form rst-form> 里。

<fieldset rst-field-range>
  <legend>预订</legend>
  <div rst-field-row data-rst-range>
    <div rst-field>
      <label rst-field-label for="dr_from">从</label>
      <input rst-input id="dr_from" name="dr_from" type="date" value="2026-09-04" 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>
    <div rst-field>
      <label rst-field-label for="dr_to">至</label>
      <input rst-input id="dr_to" name="dr_to" type="date" value="2026-09-01" aria-invalid="true" aria-describedby="dr_to-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="dr_to-error">结束早于开始。</small>
    </div>
  </div>
</fieldset>