jquery打开日历到特定的月份 [英] jquery open calendar to specific month

查看:122
本文介绍了jquery打开日历到特定的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击文本框后,当前月份会打开一个日历。我想打开日历到特定日期。目前,日历打开到当前月视图。有人可以帮我这个吗?谢谢!



选择日期:< input type =textid =datepicker/> / p>

  $('#datepicker')。datepicker({
dateFormat:'mm-dd-yy',
beforeShowDay:enableAllTheseDays,
onSelect:function(date,inst){
// MyLogic
}
});


解决方案

您可以使用 defaultDate 选项以打开特定日期。让我们假设你想要在2014年7月1日开放:

  $('#datepicker')。datepicker({
dateFormat:'mm-dd -yy',
beforeShowDay:enableAllTheseDays,
defaultDate:new Date(2014,6,1)
onSelect:function(date,inst){
// MyLogic
}
});

日期格式为年/月/日。 注意:该月份为月 - 1,所以1月(1月)为0,2月(2月)为1。



另外,你也可以这样指定相同的日期:

  $('#datepicker')。datepicker({ 
dateFormat:'mm-dd-yy',
beforeShowDay:enableAllTheseDays,
defaultDate:new Date('2014年7月1日')
onSelect:function(date,inst){
// MyLogic
}
});

您还可以像这样定义 defaultDate

  $('#datepicker')。datepicker({
dateFormat:'mm-dd-yy'
beforeShowDay:enableAllTheseDays,
defaultDate:new Date('7/1/2014')
onSelect:function(date,inst){
// MyLogic
}
});


On click of textbox, a calendar opens with current month. I want to open the calendar to specific date.Currently, the calendar opens opens to current month view. Can some one please help me with this? Thanks!

Select Date: <input type="text" id="datepicker"/>

 $('#datepicker').datepicker({ 
     dateFormat: 'mm-dd-yy', 
     beforeShowDay: enableAllTheseDays, 
     onSelect: function (date, inst) { 
        //MyLogic 
     }
 });

解决方案

You can use the defaultDate option to open to a specific date. Let's assume you want it to open to July 1st, 2014:

$('#datepicker').datepicker({ 
     dateFormat: 'mm-dd-yy', 
     beforeShowDay: enableAllTheseDays, 
     defaultDate: new Date(2014, 6, 1)
     onSelect: function (date, inst) { 
        //MyLogic 
     }
});

The format for date is year/month/day. Note: for the month, it is month - 1. So January (1st month) would be 0 and February (2nd month) would be 1.

Alternatively, you can also specify the same date like so:

$('#datepicker').datepicker({ 
     dateFormat: 'mm-dd-yy', 
     beforeShowDay: enableAllTheseDays, 
     defaultDate: new Date('1 July 2014')
     onSelect: function (date, inst) { 
        //MyLogic 
     }
});

You can also define the defaultDate like so:

$('#datepicker').datepicker({ 
     dateFormat: 'mm-dd-yy', 
     beforeShowDay: enableAllTheseDays, 
     defaultDate: new Date('7/1/2014')
     onSelect: function (date, inst) { 
        //MyLogic 
     }
});

这篇关于jquery打开日历到特定的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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