簡體   English   中英

如何在啟動日期選擇器中將startDate設置為月初?

[英]how to set startDate to beginning of the month in bootstrap datepicker?

我有兩個文本字段,一個是開始日期,另一個是結束日期。 對於開始日期,我想將月初設置為默認值。 但沒有得到如何實現這一目標。

這是我的代碼

<%= javascript_include_tag 'bootstrap-datepicker.js'%>

<%= form_tag '/mine', :class => "form-inline" do %>
 <%= label_tag 'start_date', 'Start Date' %>
 <%= text_field_tag 'start_date', nil, :class => 'calendar1' %>
 <%= label_tag 'end_date', 'End Date' %>
 <%= text_field_tag 'end_date', nil, :class => 'calendar' %>
<% end %>

<script>
$(".calendar").datepicker({format: "dd/mm/yyyy"});
$(".calendar1").datepicker({format: "dd/mm/yyyy"});
</script>

我通過引用這里嘗試過

$(".calendar1").datepicker({format: "dd/mm/yyyy", startDate: Date.today.beginning_of_month});
or
$(".calendar1").datepicker({format: "dd/mm/yyyy",setDate date(Date.today.beginning_of_month)});

您可以這樣:

<%= text_field_tag 'start_date', Date.today.beginning_of_month.strftime('%d/%m/%Y'), :class => 'calendar1' %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM