【问题标题】:jQuery Datepicker - keep open after selecting a date and close with the button "Done"jQuery Datepicker - 选择日期后保持打开并使用“完成”按钮关闭
【发布时间】:2015-09-25 13:12:12
【问题描述】:

我真诚地希望您能帮助我,因为我花了很长时间在网上搜索合适的解决方案,但找不到任何解决方案。

我遇到的问题是我有一个 jQuery 日期选择器,我希望在选择日期后保持打开状态,然后在单击其下方的“完成”按钮时将其关闭。我发现的最接近的东西来自 2012 年的 StackOverflow answer,但不幸的是它隐藏了来自 showButtonPanel: true 选项的按钮。

所以这是我最近一次“尝试”的快照,但它再次不起作用:

$(function() {
  $(".datepicker").datepicker({
    showButtonPanel: true,
    onSelect: function(){
      $(this).val();
    }
  });
});

日历从以下位置触发:

<input class="datepicker" type="text" path="startDate" data-date-format="mm/dd/yyyy" />

仅供参考 - 我正在使用 jQuery 1.7.2.min.js(不幸的是,出于安全和安保原因我无法更新)、jQuery-ui 1.10.3,当然还有 Bootstrap(版本 3.0.3 虽然我不确定这是否会有所帮助)。 谢谢

【问题讨论】:

    标签: jquery jquery-ui datepicker jquery-ui-datepicker


    【解决方案1】:

    这是一个有效的小提琴:http://jsfiddle.net/9uc7dwoa/

    这在 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;
    }
    

    这里是使用代码的答案参考: jQuery Datepicker: Prevent closing picker when clicking a date

    【讨论】:

    • 感谢您抽出宝贵时间回答我的问题,@ggzone。我现在已经实现了它,但是有一个新问题。一旦我点击一天,它不会关闭日历,它会保留按钮,但它会将我带到页面顶部。我注意到 URL 在末尾添加了一个井号标签(例如:在点击日期之前 - www.example.com/test;在点击一天之后 - www.example.com/test#)。所以它仍然不是完全有效的解决方案。另外,我在您的小提琴中看到您正在使用 jquery 1.9.1,正如我在原始帖子中提到的那样,我必须使其与 1.7.2 一起使用
    • 您的答案在错误中解决,this._get is not a function
    猜你喜欢
    • 2019-12-19
    • 2014-07-25
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 2018-07-13
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多