How to customize jquery ui date picker?

眉间皱痕 提交于 2019-12-13 02:56:30

问题


I want to customize jquery ui date picker by setting server date as current date.

After refering a question

i wrote down

var queryDate = '2012-11-15',
    dateParts = queryDate.match(/(\d+)/g)
    realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);  
                                // months are 0-based!


$('#datepicker').datepicker('setDate', realDate);
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });

it works, but when i change second step to

$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd',minDate: 0,maxDate: '+6M' });

it shows dates according to the system date not the server date which i had assigned,

How to solve this??


回答1:


You can just set the value of the input field to be a value from the server side:

<script>
var queryDate = '2012-02-25';
var dateParts = queryDate.match(/(\d+)/g);

var realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);

var min_date = new Date(2012, 2 - 1, 25 - 20); //feb 5 is the min date
var max_date = new Date(2012, 2 - 1, 25 + 1); //feb 26 is the max date

$( "#date" ).datepicker({dateFormat: 'yy-mm-dd', minDate: min_date, maxDate: max_date});
$( "#date" ).datepicker("setDate", realDate);
</script> 

In this case we are setting the date to 2012-02-25. In order for this to work you must set the format of the datepicker to be the same as the format that you've used for the value which is 'Y-m-d'



来源:https://stackoverflow.com/questions/13889379/how-to-customize-jquery-ui-date-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!