I am using the jquery event search datepicker in my code which is pr开发者_Python百科esent here . I am new to jquery and I am using the exact same code. The default date is set to one week ahead of the current date.
how do i make the default date to the current day? (simple question, but what is the correct format to do so?).
since i am using 2 fields from and to, i then want the default date to be changed according to the value selected in from field. suppose i select 20th june 2009, i want the TO field to show up from 21st June 2009 and not the current date. Can this be even done (too good that jquery automatically disables all the dates that fall before the FROM field).
i tried to change the dateformat with this code,
dateformat: "yy-mm-dd",
but it does not change.. shows the default way of mm/dd/yyyy.can i disable the from and two fields, i do not want anyone trying to manually change those values.
Code:
$(function() {
var dates = $( "#from,#to" ).datepicker({
defaultDate: "null",dateFormat: "yy-mm-dd",
changeMonth: true,disabled:true,
numberOfMonths: 3,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" );
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
$(function() {
var dates = $( "#from, #to" ).datepicker({
minDate: 0,
dateFormat: 'dd/mm/yy',
changeMonth: true,
numberOfMonths: 1,
showOn: "both",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
onSelect: function( selectedDate ) {
if(this.id=="from"){
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" );
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
var date2 = $('#from').datepicker('getDate', '+1d');
date2.setDate(date2.getDate()+1);
dates.not( this ).datepicker("option", option, date2);
}
}
});
Change
defaultDate: "+1w"
, see explanation for the option defaultDate one the page you've indicated.Change the code in
onSelect: function( selectedDate ) {
to choose the date for the second selector to be "the next day".dateFormat
, notdateformat
When you want to disable them, use
$("#from,#to").datepicker("disable")
More generally the documentation in jquery UI is really good : try to look at all option/methods available and find the one that will do what you are looking for.
精彩评论