JQuery实现先择年份和月份,不要日

首先,要有以下几个文件

<link href="include/jquery-ui-1.7.3.custom.css" type="text/css" rel="Stylesheet"/>
<SCRIPT Language="JavaScript" src="include/jquery-1.3.2.min.js"></SCRIPT>
<SCRIPT Language="JavaScript" src="include/jquery-ui-1.7.3.custom.min.js"></SCRIPT>
<SCRIPT Language="JavaScript" src="include/ui.datepicker-zh-CN.js"></SCRIPT>

然后,就可以开始写初始化代码了,

<script type="text/javascript">
jQuery(function() {
jQuery('.date-picker').datepicker( {
showMonthAfterYear: true,
changeYear: true,
changeMonth: true,
showButtonPanel: false,
dateFormat: 'yy-mm',
nextText: '下个月',
prevText: '上个月',
hideIfNoPrevNext: false,
onClose: function(dateText, inst) {
var month = jQuery("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = jQuery("#ui-datepicker-div .ui-datepicker-year :selected").val();
jQuery(this).datepicker('setDate', new Date(year, month, 1));
document.getElementById("actDate").value = year + '-' + (parseInt(month)+parseInt(1)) + '-' + '01';
},
beforeShow : function(input, inst) {
if ((datestr = jQuery(this).val()).length > 0) {
year = datestr.substring(0,4);
month = datestr.substring(5);
jQuery(this).datepicker('option', 'defaultDate', new Date(year, month-1, 1));
jQuery(this).datepicker('setDate', new Date(year, month-1, 1));
}
}
});
});
</script>

以下css用于屏蔽日的选择界面,而只有年份和月份,

<style>
.ui-datepicker-calendar
{
display: none;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值