jQuery datepicker not working with iPad

一个人想着一个人 提交于 2019-12-11 18:29:25

问题


 $(function () {
        $('.Month-Picker').datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: false,
            dateFormat: 'MM-yy',
            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).datepicker('setDate', new Date(year, month, 1));
                $("#<%=btnMonthYear.ClientID %>").click();
            },
            beforeShow: function (input, inst) {
                if ((datestr = $(this).val()).length > 0) {
                    year = datestr.substring(datestr.length - 4, datestr.length);
                    month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames'));
                    $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            }
        });
    });

I have a jQuery datepicker through which I choose the "Month-Year" Its working fine with every browser except the iPad. Please have look at the enclosed image.


回答1:


var postForm = false;

    $(function () {
        $('.Month-Picker').datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: false,
            dateFormat: 'MM-yy',
            onChangeMonthYear: function () { postForm = 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).datepicker('setDate', new Date(year, month, 1));
                $("#<%=btnMonthYear.ClientID %>").click();
            },
            beforeShow: function (input, inst) {
                if ((datestr = $(this).val()).length > 0) {
                    year = datestr.substring(datestr.length - 4, datestr.length);
                    month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames'));
                    $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
                    $(this).datepicker('setDate', new Date(year, month, 1));
                    postForm = false;
                }
            }
        });
    });

    $(document).ready(function () {
        $("#aspnetForm").click(function () {
            if (postForm == true) {
                postForm = false;
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).datepicker('setDate', new Date(year, month, 1));
                $("#<%=btnMonthYear.ClientID %>").click();
            }
        });
    });



回答2:


I suggest you to use chrome developer tools.(F12)

Settings> Overrides> "User Agent" select iPad.

Both Chrome and Safari using WebKit. You can Easily emulate iPad and debug.



来源:https://stackoverflow.com/questions/14404802/jquery-datepicker-not-working-with-ipad

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