This website requires JavaScript.
混撰

JS之input禁用tab换档键切换输入框

2020.01.24 09:37 

5 人喜欢
967 次阅读
0 条评论
var el = document.getElementsByTagName('input') // 拿到所有的input并进行遍历
for (let i = 0; i < input.length; i++) {
      el = input[i]
      el.addEventListener("keydown", function (e) {
        var keyCode = e.keyCode || e.which;

        if (keyCode === 9) {
          var start = el.selectionStart,
            end = el.selectionEnd;

          el.value = el.value.substring(0, start)
            + "\t"
            + el.value.substring(end);

          el.selectionStart = el.selectionEnd = start + 1;

          e.preventDefault();
        }
      })
}
  • 😃
  • 😂
  • 😅
  • 😉
  • 😌
  • 😔
  • 😓
  • 😘
  • 😡
  • 😭
  • 😱
  • 😳
  • 😵
  • 🌚
  • 👍
  • 👎
  • 💪
  • 🌹
  • 💊
  • 🇨🇳
  • 🇺🇸