html`<输入类型=“ number”
我有一个html < input>
带有type =“ number”
:
我想使用step
value在1。也就是说,允许任何整数。但是,我还希望箭头按钮通过某个值增加输入的值,例如5。这可能吗?
从 mdn docs ,我找不到一种方法仅使用HTML来实现这一目标。我还将接受一个涉及使用JavaScript更改输入的value
的输入
事件的答案要关键,与单击箭头按钮所引起的更改。
I have an HTML <input>
element with type="number"
:
I want to use a step
value of 1. That is, any integer is allowed. However, I would also like the arrow buttons to increment/decrement the value of the input by some value, for example, 5. Is this possible?
From the MDN docs, I can't find a way to accomplish this using HTML alone. I would also accept an answer involving intercepting the input
event using javascript to change the value
of the input, but I don't know of a way to distinguish between a change due to keypresses vs. a change due to clicking the arrow buttons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您始终可以捕获JavaScript中的输入,并使用 Parseint 将值转换为整数,并使用正常步骤来控制箭头步进。
使用此方法,您不必担心区分踏脚和输入,因为无论如何这些步骤已经是整数。
You can always capture the input in javascript and convert the values to an integer with parseInt and use the normal step to control the arrow stepping.
With this method you don't have to worry about distinguishing between the stepping and input as the steps will already be integers anyway.
&lt; label&gt;
覆盖层使
&lt; label&gt;
在&lt; input&gt;
的自旋按钮上放置,并且在EventHandler中使用.stepup()
和.stepdown()
方法当单击&lt; label&gt;
时。在示例a 中,
&lt; label&gt;
以红色概述,两个嵌套&lt; b&gt;
以蓝色概述。当然,大纲仅用于演示,很容易被删除。参见示例axy协调
另一种方式是放置一个Abspos( abs olute pos iTioned)
&lt; input&gt;
在RELPOS容器中,如果单击在&lt; input&gt;
旋转器按钮的XY坐标中,则更改步骤
属性。参见示例B 。中都评论了
示例
详细信息在示例A和B
示例B
XY坐标
<label>
OverlayMake a
<label>
that lays over the spinner button of the<input>
and in the eventhandler use the.stepUp()
and.stepDown()
methods when the<label>
is clicked.In Example A, the
<label>
is outlined in red and the two nested<b>
are outlined in blue. The outlines are just for the demo of course and can be easily removed. See Example AXY Coordinates
Another way is to place an abspos (absolute positioned)
<input>
in a relpos container and change thestep
attribute if the click is within the xy coords of the<input>
spinner button. See Example B.Details are commented in both Example A and B
Example A
<label>
overlayExample B
XY Coordinates
目前,无法直接捕获单击旋转器,但是有单击它们。
通过使用不同的事件,可以暂时调整步长。但是,如果用户使用鼠标单击旋转器,将鼠标按下并按下箭头键向上/向下按:
Currently it is not possible to capture a click on the spinners directly, but there are some ways to detect a click on them.
By using different events it is possible to adjust the step size for the moment. But it may cause some unwanted effect if the user uses the mouse to click on a spinner, keeps the mousekey pressed and presses an arrow key up/down: