gpt4 book ai didi

javascript - 自动关闭不适用于日期选择器

转载 作者:行者123 更新时间:2023-12-03 03:53:58 25 4
gpt4 key购买 nike

我在日期选择器中有自定义按钮。按钮文本:完成。

要求:当我单击文本框时,日期选择器应显示并选择某个日期。单击“完成”按钮后,所选日期应显示在文本框中,并且日期选择器应关闭。

我已将自动关闭设置为false

实际输出:单击带有“完成”按钮的文本框时,我得到了日期选择器,但是每当我选择任何日期时,日期选择器就会关闭。

我做错了什么或者必须附加更多代码吗?

$(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" />

最佳答案

查看jQuery UI Datepicker API ,似乎没有 autoclose 选项。

利用 this SO post 中的代码添加到 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>

关于javascript - 自动关闭不适用于日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45037372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com