【发布时间】:2016-06-20 21:43:22
【问题描述】:
我有一个加号/减号按钮,您可以在其中仅在输入字段中插入数值,或单击加号/减号按钮选择一个值。当您在文本字段内单击并尝试删除或退格它不起作用的数字时。这是 html 和我的小提琴的链接。更新:删除键在 Chrome 中有效,但在 Firefox 中无效。 https://jsfiddle.net/714dxayk/5/
<span class="form-title">Quantity</span>
<form id='myform' method='POST' action='#' class="numbo">
<input type='button' value='-' class='qtyminus' field='quantity' style="font-weight: bold; font-size:18px;" />
<input type='text' name='quantity' value='1' class='qty' style="margin-bottom: 0px !important" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/>
<input type='button' value='+' class='qtyplus' field='quantity' style="font-weight: bold; font-size:18px;" />
</form>
【问题讨论】:
-
我没有看到那里的脚本,你怎么能说不工作?
-
我没有放 javascript,因为这不是我要解决的问题。
-
如果有帮助的话,我用 javascript 编辑了我的小提琴。
-
onkeypress='return event.charCode >= 48 && event.charCode <= 57'看起来会拒绝所有非数字按键。 -
你为什么使用键码而不是实际值?
标签: javascript html input