开发者

jquery datepicker event search questions

开发者 https://www.devze.com 2023-01-17 17:22 出处:网络
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 th

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.

  1. how do i make the default date to the current day? (simple question, but what is the correct format to do so?).

  2. 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).

  3. 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.

  4. 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);
        }
        }
    });


  1. Change defaultDate: "+1w", see explanation for the option defaultDate one the page you've indicated.

  2. Change the code in onSelect: function( selectedDate ) { to choose the date for the second selector to be "the next day".

  3. dateFormat, not dateformat

  4. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号