Firefox - 允许在文本字段中全选,同时只允许数字和句点

Firefox - allow Select All in text field while allowing only numbers and period

本文关键字:许数字 数字 句点 文本 字段 Firefox 全选      更新时间:2023-09-26

我想出了以下代码来限制货币输入。用户可以使用主页、结束键和箭头键,但 ctrl + a 被阻止,因为 FireFox 无法识别组合键。这在Chrome和IE中可以正常工作。

有没有办法允许在FireFox中的一个字段中选择所有内容,或者这是FireFox中的一个错误?(或者可能是我正在"利用"的其他浏览器中的错误?

function autoFormatNumeric(field, e) {
  var charCode = e.which ? e.which : field.keyCode;
  if ((charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) ) {
    e.preventDefault();
  }
}
$("#myInput").on('focus',function(){
  $(this).select(); // <- This jquery function select all even in firefox
});