jquery-ui日期插件datepicker仅显示年月且含有全部按钮

1.日历插件仅显示年月,需要在html中作如下处理:

<style type="text/css">
    .ui-datepicker-calendar {
        display: none;
    }
</style>

2.因业务需要,需要查询全部,故使用清除按钮做为全部

时间:<input type="text" validate alias="时间" id="datePickerMon" class="form-control data-choose-width" placeholder="请选择"/>

js代码:

$('#datePickerMon').datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'yy-mm',
    showButtonPanel: true,
    monthNamesShort: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
    closeText: '选择',
    currentText: '本月',
    isSelMon:'true',
    onClose: function (dateText, inst) {
        var month = +$("#ui-datepicker-div .ui-datepicker-month :selected").val() + 1;
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        if (month < 10) {
            month = '0' + month;
        }
        this.value = year + '-' + month;
        if (typeof this.blur === 'function') {
            this.blur();
        }
        $scope.query(1);
    },
    beforeShow: function(input) {
        setTimeout(function() {
            var buttonPane = $(input).datepicker( "widget" ).find( ".ui-datepicker-buttonpane" );

            $( "<button>", {
                text: "全部",
                click: function() {
                    $.datepicker._clearDate(input);
                    $('#datePickerMon').val("全部");
                    //查询全部的列表清单
                    $scope.query(1);
                }
            }).addClass("ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all").appendTo( buttonPane );
        }, 1 );
    }
});

效果如下:

注:此为个人笔记及总结,有误或有更好的解决方案请指正!谢谢  

猜你喜欢

转载自blog.csdn.net/shenyi_198812/article/details/84834770