2

我需要在 jQuery UI Datepicker 中添加一个自定义按钮,当用户单击该按钮时,设置一个输入值(文本字符串)并关闭弹出窗口。这可能吗?

小提琴示例:http: //jsfiddle.net/7Wygg/

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">Custom</button>');
        btn.unbind("click")
        .bind("click", function () {
            //$.datepicker._clearDate(input);
            alert('custom text');
        });

        btn.appendTo(buttonPane);

    }, 1);
}

谢谢你。

4

2 回答 2

7

由于评论而修改了答案

你的意思是这样的:http: //jsfiddle.net/7Wygg/10/

我刚刚添加

$(input).datepicker("hide");
$(input).val("custom text");
于 2013-08-22T11:18:49.430 回答
2

set a demo HERE and here in datepicker we can set date like pattern not any other

$(function() {
$(".datepicker").datepicker({
    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">Custom</button>');
            btn.unbind("click")
            .bind("click", function () {
                //$.datepicker._clearDate(input);
                alert('custom text');
                $(".datepicker").datepicker( "hide" );
                $( ".datepicker" ).datepicker( "setDate", "19/12/2003" );// here in cutom we can set date like pattern not any other

            });

            btn.appendTo(buttonPane);

        }, 1);
    }
});
});
于 2013-08-22T11:22:54.820 回答