This question already has answers here:
HTML text input allow only numeric input
(60个答案)
3个月前关闭。
我输入的内容是用户只能输入数字或浮点数。如果我输入文字会清除整个输入。我要禁止输入文字而不清除字段。任何想法如何做到这一点?
(60个答案)
3个月前关闭。
我输入的内容是用户只能输入数字或浮点数。如果我输入文字会清除整个输入。我要禁止输入文字而不清除字段。任何想法如何做到这一点?
<input
type="text"
id="willBeCreditedAmount"
maxLength={9}
placeholder="Enter amount"
pattern="[0-9]*"
onChange={(e) => this.props.updateWillBeCreditedAmount(e.target.value, currentComProfile)
}
value={willBeCreditedAmount}
/>
最佳答案
您可以使用此代码
<form>
<input type="number" id="myNumber" value="1">
</form>
关于html - 如何使输入表单仅包含数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58411987/