Tag: 推荐引擎

哪种方法可以过滤文本字段的数值?

我正在开发一个文本字段,使用那种不允许您输入数字值以外的validation。 因此,我的初始代码看起来很简单,与此类似: $(textField).onKeyPress(function(e) { if (e.which 57) e.preventDefault(); }); 这是非常明确的,但转向(在所有浏览器的最新版本中)Firefox也会使用箭头键和删除/退格键来阻止移动,而其他浏览器则不会。 环顾四周,我发现我还需要检查这些键,并检查e事件参考中公开的不同属性。 我的最终代码看起来像这样: $(textField).onKeyPress(function(e) { var code = e.which || e.keyCode; if (code > 31 // is not a control key && (code 40) // is not an arrow key && (code 57) // is not numeric && (code != 46) // is not the delete […]