【问题标题】:input type="number" is not able to delete/clear on selecting the number in Firefox and IEinput type="number" 在 Firefox 和 IE 中选择数字时无法删除/清除
【发布时间】:2018-04-30 20:32:28
【问题描述】:

我已验证接受输入 type="number" 字段的最小值和最大值。一旦我输入了一些输入,它就会根据最大值和最小值工作。我的问题是我无法清除/删除数字字段中输入的值。在文本框字段中,允许通过使用退格键并选择数字并键入新数字来清除值。为什么数字字段在这种情况下不起作用。如何清除/删除数字字段中的数字。

  <input type="number" name="WorkingDaysPA" id="WorkingDaysPA"
             min="1" max="366" style="text-align: right"

             onkeypress="if(this.value.length==3) return false;return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57"
         />

<input type="text" maxlength="3" min="1" max="366">

这是我的小提琴:https://jsfiddle.net/MariNithya/fpd2y4f4/

【问题讨论】:

  • 小提琴链接断开。
  • 现在,小提琴正在工作。

标签: javascript html angularjs


【解决方案1】:

在焦点事件中,我将 null 作为值;

希望对你有帮助

document.getElementById("validateNums").addEventListener("focusout", inputOutOfFocus);
function inputOutOfFocus() {
 document.getElementById("validateNums").value = null;
}
&lt;input type="number" maxlength="3" min="1" max="366" id="validateNums"&gt;

【讨论】:

  • 这适用于输入类型="text"。没有这个也文本框清除选择值的值并输入新值。但我需要的是 input type="number"
  • 在 chrome 中,我可以清除在为 input type="number" 选择数字时已经输入的值但是,在 Firefox 和 IE 中不起作用
  • 你用的是什么版本的火狐?我在 Firefox 55 版中对其进行了测试,它可以工作;默认情况下不会;但上面的代码使它工作;我没有 IE;所以不能对此发表评论;
  • 火狐 57.0.上面的代码适用于数字和文本类型?
  • 是的,它也对我有用。但是当我不使用箭头键手动输入数字时,最大值验证不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-16
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 2018-11-01
  • 2011-09-05
相关资源
最近更新 更多