Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用month&;在jquery中开发依赖日期选择器;使用jquery的年份_Javascript_Jquery_Html_Jquery Ui_Datepicker - Fatal编程技术网

Javascript 如何使用month&;在jquery中开发依赖日期选择器;使用jquery的年份

Javascript 如何使用month&;在jquery中开发依赖日期选择器;使用jquery的年份,javascript,jquery,html,jquery-ui,datepicker,Javascript,Jquery,Html,Jquery Ui,Datepicker,我已经有了一个JSFIDLE,但是它没有按照预期工作,如果用户直接选择结束日期,它就不会限制这个FIDLE中的开始日期。一旦用户直接更改结束日期,则必须更改结束日期。首先选择开始日期可以很好地工作。当用户直接选择结束日期时,它不起作用。请帮助我 $(document).ready(function() { $("#projectStartDate").datepicker({ dateFormat: 'MM yy',

我已经有了一个JSFIDLE,但是它没有按照预期工作,如果用户直接选择结束日期,它就不会限制这个FIDLE中的开始日期。一旦用户直接更改结束日期,则必须更改结束日期。首先选择开始日期可以很好地工作。当用户直接选择结束日期时,它不起作用。请帮助我

$(document).ready(function() {
            $("#projectStartDate").datepicker({
                dateFormat: 'MM yy',
                changeMonth: true,
                changeYear: true,
                maxDate:'-1M',
                yearRange:'1975:c+10',
                showButtonPanel: true,
                onClose: function(dateText, inst) {
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();

                    $(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));


              }


            });
            $("#projectStartDate").focus(function() {
                $(".ui-datepicker-calendar").hide();
                $("#ui-datepicker-div").position({
                    my: "center top",
                    at: "center bottom",
                    of: $(this)
                });
            });
        });



        $(document).ready(function() {
            $("#projectCompletedDate").datepicker({
                dateFormat: 'MM yy',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                minDate: $("#projectStartDate").datepicker('getDate'),
                maxDate:0,
                yearRange:'1975:c+10',
                onClose: function(dateText, inst) {
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();


                    $(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));


                }
            });
            $("#projectCompletedDate").focus(function() {
                $(".ui-datepicker-calendar").hide();
                $("#ui-datepicker-div").position({
                    my: "center top",
                    at: "center bottom",
                    of: $(this)
                });
            });
        });

这是小提琴链接

只需将这些行添加到

$(“#第一个日期选择器”)关闭事件

$("#second-datepicker").datepicker("option", "minDate", dateText);
$("#first-datepicker").datepicker("option", "maxDate", dateText);
和$(“#第二个日期选择器”)关闭事件

$("#second-datepicker").datepicker("option", "minDate", dateText);
$("#first-datepicker").datepicker("option", "maxDate", dateText);
最终代码:

$('#first-datepicker').datepicker({
        changeYear: true,
        changeMonth: true,
        beforeShow: function (input, inst) {
            setMyDate(inst);
        },
        onClose: function (dateText, inst) {
            saveMyDate(inst);

            var secondDatePicker = $('#second-datepicker').data('datepicker');
            var dateSetted = secondDatePicker.input.data('date-setted');

            setMyDate(secondDatePicker);

            secondDatePicker.input.datepicker('option', 'minDate', new Date(inst.selectedYear, inst.selectedMonth, 0));     

            if (dateSetted == true) {
                saveMyDate(secondDatePicker);
            };

            $("#second-datepicker").datepicker("option", "minDate", dateText);
        }
    });

    $('#second-datepicker').datepicker({
        changeYear: true,
        changeMonth: true,
        beforeShow: function (input, inst) {
            setMyDate(inst);
        },
        onClose: function (dateText, inst) {
            saveMyDate(inst);
            $("#first-datepicker").datepicker("option", "maxDate", dateText);
        }
    });

请改进您的问题,您必须使用JSFIDLE添加代码。你的描述也有语言错误,我不知道你的意思。现在请看清楚了