在数字输入中按backspace键时避免历史回溯

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在数字输入中按backspace键时避免历史回溯相关的知识,希望对你有一定的参考价值。

Avoid history back when is pressed backspace key in number imput
  1. $('input[type=number]').on('keydown', function(e) {
  2. var key = e.which || e.keyCode || e.charCode;
  3. if (key === 8) {
  4. var s = $(this).val();
  5. s = s.substring(0, s.length - 1);
  6. $(this).val(s);
  7. return false;
  8. }
  9. });

以上是关于在数字输入中按backspace键时避免历史回溯的主要内容,如果未能解决你的问题,请参考以下文章