jquery-ui – 如何在按钮面板中将按钮添加到jQuery datepicker?

前端之家收集整理的这篇文章主要介绍了jquery-ui – 如何在按钮面板中将按钮添加到jQuery datepicker?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是将元素附加到面板包装器并调用.button()?

解决方法

如果要在滚动月份期间保持“清除”按钮,请使用onChangeMonthYear:。

一个例子:

$( "#datepicker" ).datepicker({
    showButtonPanel: true,beforeShow: function( input ) {
        setTimeout(function() {
            var buttonPane = $( input )
                .datepicker( "widget" )
                .find( ".ui-datepicker-buttonpane" );

            $( "<button>",{
                text: "Clear",click: function() {
                //Code to clear your date field (text Box,read only field etc.) I had to remove the line below and add custom code here
                    $.datepicker._clearDate( input );
                }
            }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");
        },1 );
    },onChangeMonthYear: function( year,month,instance ) {
        setTimeout(function() {
            var buttonPane = $( instance )
                .datepicker( "widget" )
                .find( ".ui-datepicker-buttonpane" );

            $( "<button>",read only field etc.) I had to remove the line below and add custom code here
                    $.datepicker._clearDate( instance.input );
                }
            }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");
        },1 );
    }
});

猜你在找的jQuery相关文章