使用按钮而不是文本输入时,更改事件的jQuery Datepicker未触发

时间:2019-02-01 19:14:36

标签: javascript jquery datepicker

我正在尝试使用jQuery dtaepicker将按钮设置为仅日期选择器。

将日期选择器附加到输入时,onchange函数起作用,并且我得到了新的选定值。

但是,当我仅用一个按钮或其他附件附加日期选择器时,不会触发onchange事件:

...
#include <pangomm/init.h>

int main()
{
    Pango::init();

    ...
}

4 个答案:

答案 0 :(得分:1)

使用hide事件 - 它会火,你完成插入或选择一个日期后:

$(function() {
            $(".test").datepicker({
              format: 'yyyy-mm-dd',
              onSelect: function(v) {
                // also not getting fired
              },
            }).on("hide", function(e) {
              // not getting fired when using button instead of text input
              let val = $(this).val();
            });
        });

答案 1 :(得分:0)

您可以尝试答案here

您应该能够调用从按钮单击事件的日期选择器改变

答案 2 :(得分:0)

我认为你需要添加此行showOn: 'button'

<input type="text" class="test"> // works

<i class="fa fa-calendar test"></i> // opens the datepicker as should be, but not fire the change event

$(function() {
            $(".test").datepicker({
              showOn: 'button', // use showOn: 'both' if you want to open the datepicker on icon and the input as well
              format: 'yyyy-mm-dd',
              onSelect: function(v) {
                // This would get fired on changing date on the calendar icon
              },
            }).on("change", function() {
              // not getting fired when using button instead of text input
              let val = $(this).val();
            });
        });

此外,您可以删除<i class="fa fa-calendar test"></i>标记并将以下两个LOC放在showOn属性之后以显示日历图标

  buttonImageOnly: true,
  buttonImage: 'http://jqueryui.com/resources/demos/datepicker/images/calendar.gif',

答案 3 :(得分:0)

我找到了它:

$(".test").datepicker(params).on('hide', v => console.log(v.date));
// will return a date object with the selected date