最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to update Jquery Datepicker with a variable? - Stack Overflow

programmeradmin1浏览0评论

I have a form with Jquery Datepicker and i can save the date in the database.

But when i reload the form to update the datas, i would like to have Jquery Datepicker showing the date previoulsy recorded in the database.

I can load it with php. I just need to update the datepicker.

In the documentation, i see :

beforeShowType: Function( Element input, Object inst ) Default: null A function that takes an input field and current datepicker instance and returns an options object >to update the datepicker with. It is called just before the datepicker is displayed.

I think it can be the solution. Could someone give me an example ?

I have a form with Jquery Datepicker and i can save the date in the database.

But when i reload the form to update the datas, i would like to have Jquery Datepicker showing the date previoulsy recorded in the database.

I can load it with php. I just need to update the datepicker.

In the documentation, i see :

beforeShowType: Function( Element input, Object inst ) Default: null A function that takes an input field and current datepicker instance and returns an options object >to update the datepicker with. It is called just before the datepicker is displayed.

I think it can be the solution. Could someone give me an example ?

Share Improve this question asked Oct 11, 2012 at 21:12 Sébastien GicquelSébastien Gicquel 4,3867 gold badges57 silver badges87 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

What did you attach the datepicker to? If you attached it to an input, then you just need to set the value of the input before calling datepicker() on it.

If you haven't initialized the datepicker yet, you can do:

$( '#yourElement' ).datepicker({ defaultDate: yourDate });

Otherwise, you can call the setDate method to set the date on an already initialized datepicker:

$( '#yourElement' ).datepicker( 'setDate', yourDate );
发布评论

评论列表(0)

  1. 暂无评论