【问题标题】:Firefox - allow Select All in text field while allowing only numbers and periodFirefox - 允许在文本字段中全选,同时只允许数字和句点
【发布时间】:2013-10-08 22:21:19
【问题描述】:

我想出了以下代码来限制货币输入。用户可以使用 home、end 和箭头键,但 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();
  }
}

【问题讨论】:

    标签: javascript jquery firefox


    【解决方案1】:
    $("#myInput").on('focus',function(){
      $(this).select(); // <- This jquery function select all even in firefox
    });
    

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 2021-10-07
      • 2010-10-24
      • 2013-02-19
      相关资源
      最近更新 更多