私信  •  关注

olissongs

olissongs 最近回复了
6 年前
回复了 olissongs 创建的主题 » <input type=“date”>-jquery catch事件清除日期

谢谢你,基思,这对我的解决方案很有帮助。

我在项目中使用了jquery,所以我需要jquery中的解决方案。

这个js解决方案解决了一个问题,但另一个问题是:如果通过单击clear按钮(“x”)加载页面并删除日期值,则change事件无法识别它。解决方案:

$('.date-input')
    .click(function(e) {
         $(this).focus();
    }
    .change(function(e) {
         var myValue = $(this);
         if (!myValue.val()) {
            // do something when cleared
         } else {
            // do something on changed date
         }
    });

HTML:

<input type="date" class="date-input" />