首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动关闭不适用于日期选择器

问自动关闭不适用于日期选择器
EN

Stack Overflow用户
提问于 2017-07-11 14:27:29
回答 2查看 1K关注 0票数 1

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

要求:当我点击文本框时,日期选择器应该显示并选择一些日期。单击“完成”按钮后,选定的日期应显示在文本框中,日期选择器应关闭。

我已经将自动关闭设置为false。

实际输出:在textbox上单击"Done“按钮时得到日期选择器,但是每当我选择任何日期时,日期选择器都会关闭。

我是不是做错了什么或者必须追加更多的代码。

​

代码语言:javascript
复制
$(function () {
  $(".datepicker1").datepicker({
    showButtonPanel: true,
    autoclose: false,
    dateFormat: "yy-mm-dd",
    onSelect: function (dateText, inst) {
        alert('Date Selected');
    }
  });
});
代码语言:javascript
复制
<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"  />

​

EN

回答 2

Stack Overflow用户

发布于 2017-07-11 14:40:04

从jQuery UI数据采集API上看,似乎没有autoclose选项。

利用来自这是如此的帖子的代码添加到onSelect事件:

​

代码语言:javascript
复制
$().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;
        }
      }});
    });
代码语言:javascript
复制
<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>

​

票数 1
EN

Stack Overflow用户

发布于 2017-07-11 14:42:31

我知道答案了。

我在OnSelect事件中添加了下面的代码

代码语言:javascript
复制
 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;
                }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45037372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档