【问题标题】:The text in input value doesn't show when using input type="number"使用 input type="number" 时输入值中的文本不显示
【发布时间】:2016-12-21 13:07:31
【问题描述】:

我想将输入类型保留为“数字”。那么如何解决这个问题,如果 input type="number" 只允许将数字作为值而不是文本。

这就是我想要实现的目标:

<input type="number" name="amount" value="Other Amount">

【问题讨论】:

    标签: html css forms performance input


    【解决方案1】:

    我会使用占位符来代替值

    <input type="number" name="amount" placeholder="Other Amount">
    

    【讨论】:

      【解决方案2】:

      如果你想实现只允许数字的文本输入,你应该这样做:

      <input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
      

      你需要控制允许按下哪个字符

      【讨论】:

        猜你喜欢
        • 2014-02-08
        • 2019-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 1970-01-01
        • 2019-11-03
        • 2017-04-17
        相关资源
        最近更新 更多