jQuery datepicker adding custom button

◇◆丶佛笑我妖孽 提交于 2019-11-27 06:31:23

问题


I'm trying to add a custom button to the button panel of jQuery's datepicker. When I apply the following code though nothing happens:

 $('.date-picker').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,  
        beforeShow: function(input) {  
            setTimeout(function() {  
            var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );  
            var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');  
            btn.unbind("click").bind("click", function () {  
                $.datepicker._clearDate( input );  
            });  

            btn.appendTo( buttonPane );  

            }, 1 );  
        } ,
        dateFormat: 'MM yy',
        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));
        }
    });

Any help would be appreciated.


回答1:


$(function(){
    var pickerOpts = {
        showOn: "button"
    };  
    $("#date").datepicker(pickerOpts);
});



回答2:


A related question "How do you add buttons to a jQuery datepicker in the button panel?" was answered in another post. For an example of how a "Prev Day" and "Next Day" button was added to the button panel, see How do you add buttons to a jQuery datepicker in the button panel?



来源:https://stackoverflow.com/questions/9894032/jquery-datepicker-adding-custom-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!