最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable Scrollwheel changes to Number and Date inputs in Firefox - Stack Overflow

programmeradmin2浏览0评论

Similar to this question, I'm trying to prevent the scrollwheel form incrementing a numeric input.

In Chrome/webkit, the following works but in Firefox the wheel still changes the input.

$('input[type=number]').on('mousewheel',
    function(e){ $(this).blur(); }
);
<script src=".1.1/jquery.min.js"></script>
<input type="number">

Similar to this question, I'm trying to prevent the scrollwheel form incrementing a numeric input.

In Chrome/webkit, the following works but in Firefox the wheel still changes the input.

$('input[type=number]').on('mousewheel',
    function(e){ $(this).blur(); }
);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number">

Share Improve this question asked Dec 11, 2017 at 19:36 JosiahJosiah 3,1781 gold badge35 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Yeah, it doesn't work with firefox. This should work though :) Hope it helps.

$('input[type=number]').on('wheel', function(e){
    return false;
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="menu">

I've found a better solution using vanilla Javascript:

    document.querySelectorAll("input[type=number]").forEach(function (element) {
        element.addEventListener("wheel", function(event) {
            if (document.activeElement === event.target) {
                event.preventDefault();
            }
        });
    });
发布评论

评论列表(0)

  1. 暂无评论