问题
$(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