html5输入类型日期输入事件错误地触发空值 [英] html5 input type date input event incorrectly fires with empty value

查看:154
本文介绍了html5输入类型日期输入事件错误地触发空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是奇怪的行为,我没有能够孤立完全重现它的步骤;然而,在使用x来重置输入之后,它似乎很频繁地出现。日期重置后,使用键盘输入有效日期,然后继续切换不同的月/日/年设置。

This is odd behavior that I haven't been able to isolate the steps to reproduce it exactly; however, it seems to occur quite frequently after using the little 'x' to reset the input. After the date is reset, enter a valid date with the keyboard and then continue to toggle the various month/day/year settings.

<input id="pi-start" type="date" data-clear-btn="false" value="">

$('#pi-start').on('input', function()
{
    var value = $('#pi-start').val();
    if ( value != '' )
    {
        console.log(value);
    }
    else
    {
        console.log("Blank");
    }
});

您可以在控制台中看到更改月份时触发了输入事件,但未设置输入值。

You can see in the console where changing the month fired the input event but the value for the input wasn't set.

这里发生了什么,防止这种情况的最佳方法是什么?我希望能够检测到价值的变化。

What's going on here and what's the best way to prevent this? I want to be able to detect the change in value.

Chrome:版本64.0.3282.119(官方版本)(64位)

Chrome: Version 64.0.3282.119 (Official Build) (64-bit)

推荐答案

当然,一旦我发布了这个问题,我就知道发生了什么。为输入触发空值,因为键盘允许您选择无效的日期。即。 2月30日。

Of course once I post the question I figured out what is occurring. The empty value is fired for the input because the keyboard allows you to select a date that is not valid. ie. Feb, 30.

这篇关于html5输入类型日期输入事件错误地触发空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆