html5 input type date input event incorrectly fires with empty value

。_饼干妹妹 提交于 2019-12-18 09:38:11

问题


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: Version 64.0.3282.119 (Official Build) (64-bit)


回答1:


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.



来源:https://stackoverflow.com/questions/48564568/html5-input-type-date-input-event-incorrectly-fires-with-empty-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!