将鼠标悬停在日期时间输入字段上时禁用滚动

Disable scrolling when hovering over DateTime input field

我的一个输入字段(一个简单的编辑器,type=datetime)现在允许用户在将鼠标悬停在日期上时使用鼠标滚轮来更改日期。这种行为必须停止,因为它可能会在向下滚动页面时导致意外更改。 我已经尝试了几个建议,例如 preventDefault 和 blur,但没有一个有效...

$(function () {
    $(':input[type="datetime"]').bind('mousewheel', function (event) {
        event.preventDefault();
    });
});

我什至测试过将悬停事件添加到整体中,但在所有情况下仍然有很多可滚动性。最后,我想完全禁用此日期时间输入的鼠标滚轮值更改。

谢谢!

试试这个:

$('input[type=datetime-local]').bind("mousewheel", function () {
 return false;
});

您还应该考虑使用 datetime-local,因为 datetime was depricated