is there a way to disable 'tab' on a input type='text'?

前端 未结 3 764
南旧
南旧 2021-02-20 12:38

is there a cross-browser solution to disable \'tab\' on a input type=\'text\' ?


Pressing \'tab\' moves you to the

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 13:01

    document.querySelector('input').addEventListener('keydown', function (e) {
        if (e.which == 9) {
            e.preventDefault();
        }
    });
    

    Depends on how cross-browser you are talking though, as the above only supports IE9 (and other modern browsers).

    http://jsfiddle.net/ExplosionPIlls/YVUzz/

    IE8- use attachEvent instead of addEventListener and e.keyCode instead of e.which, and there is no preventDefault, but you can use return false.

提交回复
热议问题