如何设置jquery monthpicker的默认月份和年份 [英] How to set the default month and the year of jquery monthpicker

查看:766
本文介绍了如何设置jquery monthpicker的默认月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在页面加载时设置jquery monthpicker的默认月份和年份。

I need to set the default month and the year for the jquery monthpicker when page loads.

下面是我的代码。当前monthpicker文本框在加载时为空。

Below is my code. Currently monthpicker text box is empty when loads.

  $(document).ready(function() {      
    $('#monthPicker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
showButtonPanel: true,
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));
}
});
}); 

而且,我需要从日历中删除日期,我的意思是我只需要显示年份和月份选择选项。

And also, I need to remove the dates from the calendar, I mean I just only need to display the year and month selection options.

推荐答案

如果要在页面加载时显示默认值,只需设置日期后的日期初始化datepicker:

If you want to show a default value when the page loads, just set the date after initializing the datepicker:

$(function() {
  $('#monthPicker').datepicker( {
    // ...
  });

  var default_date = new Date(2023, 10, 1);
  $("#monthPicker").datepicker("setDate", default_date);
});

只需将日期设置为 default_date 即可。 Rembemer,在javascripts中,几个月开始 0 0 表示1月, 11 表示12月)。

Just set whatever date to default_date. Rembemer that, in javascripts, months start on 0 (0 means january, and 11 means december).

这篇关于如何设置jquery monthpicker的默认月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆