datepicker只选择年月的设置技巧

来源:互联网 发布:山海关 知乎 编辑:程序博客网 时间:2024/05/22 13:19

本文不适合初学者,建议有一定jQuery ui基础的朋友继续阅读

首先在style中屏蔽日期选择面板

<style type="text/css">.ui-datepicker-calendar {display: none;// 不显示日期面板}</style>

然后在javascript中设定onClose事件

    function showdatepicker() {        $("#dateText").datepicker({            monthNamesShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"], // 区域化月名为中文prevText: '上月',// 前选按钮提示nextText: '下月',// 后选按钮提示            changeYear: true, // 年下拉菜单            changeMonth: true, // 月下拉菜单            showButtonPanel: true, // 显示按钮面板            showMonthAfterYear: true, // 月份显示在年后面            currentText: "本月", // 当前日期按钮提示文字            closeText: "关闭", // 关闭按钮提示文字            dateFormat: "yy-mm",// 日期格式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));}        });    }


0 1
原创粉丝点击