如何在仅显示月份和年份的Datepicker中设置开始和结束月份 [英] How Do I Set Start And End Month In Datepicker Which Shows Only Month And Year
本文介绍了如何在仅显示月份和年份的Datepicker中设置开始和结束月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个显示月份和年份选择器的文本框。我想根据用户选择的文本框中的值为文本框设置思维(月份)。
这是我的jscript但它不起作用。
I have two textbox from and to which shows month and year picker. I want to set mindate(month) for to textbox from the value from textbox which user has selected.
Here is my jscript but its not working.
$(function () {
$("#<%=frm_txtdatefrm.ClientID %>").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'M yy',
showButtonPanel: true,
onClose: function () {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
$(this).datepicker('refresh');
},
beforeShow: function () {
if ((selDate = $(this).val()).length > 0) {
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
if ((selDate = $(this).val()).length > 0) {
year = selectedDate.substring(selectedDate.length - 4, selectedDate.length);
month = jQuery.inArray(selectedDate.substring(0, selectedDate.length - 5), $(this).datepicker('option', 'monthNamesShort'));
$("#<%=frm_txtdateto.ClientID %>").datepicker("option", "mindate", new Date(year, month, 1));
}
}
});
$("#<%=frm_txtdatefrm.ClientID %>").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
$("#<%=frm_txtdatefrm.ClientID %>").blur(function () {
$(".ui-datepicker-calendar").hide();
});
推荐答案
(function(){
(function () {
(#<% = frm_txtdatefrm.ClientID %> )。datepicker({
changeMonth:true,
changeYear:true,
dateFormat:'M yy',
showButtonPanel:true,
onClose:function(){
var iMonth =
("#<%=frm_txtdatefrm.ClientID %>").datepicker({ changeMonth: true, changeYear: true, dateFormat: 'M yy', showButtonPanel: true, onClose: function () { var iMonth =
(#ui-datepicker-div .ui-datepicker-month :selected)。val();
var iYear =
("#ui-datepicker-div .ui-datepicker-month :selected").val(); var iYear =
这篇关于如何在仅显示月份和年份的Datepicker中设置开始和结束月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文