【发布时间】:2018-03-13 18:09:10
【问题描述】:
我将此输入与 onkeypress 事件一起提交:
<input type="number" min = "0" id = "count" onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
基本上,这只允许在该字段中输入数字值......这很好用......在 Chrome、Firefox 和 IE 中......这对我来说已经足够了。但是“退格”键在 Firefox 中不起作用。它在 Chrome 和 IE 中运行良好。我的意思是,如果我想输入“15”,但不小心输入了“155”……在 Firefox 中,我无法在该字段上使用“退格”。如何让退格在 Firefox 中工作?
【问题讨论】:
-
按删除返回 false 并且似乎停止了默认响应
<input type="number" min = "0" id = "count" onkeypress='console.log( event.charCode >= 48 && event.charCode <= 57)' />,如您所见
标签: javascript html