Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

javascript - jQuery datepicker minDate variable

I'm usung the jQuery datepicker. In my "EndDate" textbox I'd like to use the date selected from the the "StartDate" textbox + 1. How do I do this?

I tried this but didn't work. In my start date code I had...

            test = $(this).datepicker('getDate');
            testm = new Date(test.getTime());
            testm.setDate(testm.getDate() + 1);

Then in my end date code I had...

minDate: testm,

but the end date still made all the days for the month available.


Edit. I'm curious as to why this doesn't work. In my start date datepicker I have this..

onSelect: function (dateText, inst) {
    test = dateText
}

Why can't I come down into my end date datepicker and say, minDate: test?


Edit. Still not working

    $(".dateStartDatePickerBox").datepicker({
        minDate:'-0d',
        onSelect: function(dateText, inst)
        {
            test = $(this).datepicker('getDate');
            testm = new Date(test.getTime());
            testm.setDate(testm.getDate() + 1);

            $("#dateEndDatePickerBox").datepicker("option", "minDate", testm);
        }
    });

    $(".dateEndDatePickerBox").datepicker({
        onSelect: function()
        {

        }
    });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You'll need to set the min date dynamically on the change event of the start date.

Something like:

$("#startDate").change(function() {
    test = $(this).datepicker('getDate');
    testm = new Date(test.getTime());
    testm.setDate(testm.getDate() + 1);

    $("#endDate").datepicker("option", "minDate", testm);
});

Answer to the edit:

You cannot do the following:

var test;
$("#myinput").datepicker({
    onSelect: function() { test = $(this).datepicker("getdate"); }
});
$("#myotherinput").datepicker({
    minDate: test
});

Test is uninitialized at the time that minDate is being set on myotherinput. The process of setting the minDate doubtless requires DOM manipulation which datepicker manages on initialization or when "option" is called. Simply changing the variable that was used for initialization does not effect the already initialized datepicker.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[1] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

56.9k users

...