我在日期选择器里面有自定义按钮。按钮文本:完成。
要求:当我点击文本框时,日期选择器应该显示并选择一些日期。单击“完成”按钮后,选定的日期应显示在文本框中,日期选择器应关闭。
我已经将自动关闭设置为false。
实际输出:在textbox上单击"Done“按钮时得到日期选择器,但是每当我选择任何日期时,日期选择器都会关闭。
我是不是做错了什么或者必须追加更多的代码。
$(function () {
$(".datepicker1").datepicker({
showButtonPanel: true,
autoclose: false,
dateFormat: "yy-mm-dd",
onSelect: function (dateText, inst) {
alert('Date Selected');
}
});
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input class="datepicker1" type="text" />
发布于 2017-07-11 14:40:04
从jQuery UI数据采集API上看,似乎没有autoclose选项。
利用来自这是如此的帖子的代码添加到onSelect事件:
$().ready(function () {
$(".datepicker1").datepicker({
showButtonPanel: true,
dateFormat: "yy-mm-dd",
onSelect: function (dateText, inst) {
alert('Date Selected');
// keep dialog open
if (inst.inline)
this._updateDatepicker(inst);
else {
this._hideDatepicker(null, this._get(inst, 'duration'));
this._lastInput = inst.input[0];
if (typeof(inst.input[0]) != 'object')
inst.input[0].focus(); // restore focus
this._lastInput = null;
}
}});
});<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<input class=datepicker1 type=text>
发布于 2017-07-11 14:42:31
我知道答案了。
我在OnSelect事件中添加了下面的代码
if (inst.inline) this._updateDatepicker(inst);
else {
this._hideDatepicker(null, this._get(inst, 'duration'));
this._lastInput = inst.input[0];
if (typeof (inst.input[0]) != 'object') inst.input[0].focus(); // restore focus
this._lastInput = null;
}https://stackoverflow.com/questions/45037372
复制相似问题