Javascript 使用jquery设置日期\u选择

Javascript 使用jquery设置日期\u选择,javascript,jquery,ruby-on-rails,jquery-ui-datepicker,Javascript,Jquery,Ruby On Rails,Jquery Ui Datepicker,我的表格中有一个字段: <div class="field"> <%= f.label :date %><br> <%= f.date_select :date,{order: [:day, :month, :year]}, class: "datepicker task_date" %> </div> 但是现在我想在表单提交后,选择日期和当前时间 $('.task_date').datepicker(

我的表格中有一个字段:

<div class="field">
        <%= f.label :date %><br>
        <%= f.date_select :date,{order: [:day, :month, :year]}, class: "datepicker task_date" %>
</div>
但是现在我想在表单提交后,选择日期和当前时间

$('.task_date').datepicker("defaultDate", new Date() );
我有这个,但没用,有人有主意吗

谢谢您的帮助。

您应该使用以下方法:

更新:

这对我来说很有用

//Get current date
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();

//Set date back to current date
$("#task_date_3i.datepicker.task_date").val(day);
$("#task_date_2i.datepicker.task_date").val(month);
$("#task_date_1i.datepicker.task_date").val(year);

Thanx的答案,我试过了,但还是不起作用,因为格式?
$('.task_date').datepicker('setDate', new Date());
//Get current date
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();

//Set date back to current date
$("#task_date_3i.datepicker.task_date").val(day);
$("#task_date_2i.datepicker.task_date").val(month);
$("#task_date_1i.datepicker.task_date").val(year);