javascript jQuery UI Datepicker - 自定义按钮 - 自定义文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18378786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery UI Datepicker - Custom button - Custom text
提问by FeKuLa
I need to add a custom button in jQuery UI Datepicker, and when the user clicks that button, set a value to input (a string of text) and close the popup. Is possible this?
我需要在 jQuery UI Datepicker 中添加一个自定义按钮,当用户单击该按钮时,设置一个值以输入(一串文本)并关闭弹出窗口。这可能吗?
Fiddle example: http://jsfiddle.net/7Wygg/
小提琴示例: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);
}
Thank you.
谢谢你。
回答by Rob
Modified answer due to comment
由于评论而修改答案
You mean like this: http://jsfiddle.net/7Wygg/10/?
你的意思是这样的:http: //jsfiddle.net/7Wygg/10/?
I just added
我刚加
$(input).datepicker("hide");
$(input).val("custom text");
回答by Rituraj ratan
set a demo HEREand 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);
}
});
});