HTML输入框:仅限数值

时间:2018-03-27 08:55:06

标签: html

我有一个带有输入字段的HTML表单。 我只想输入数值。

问题是,当我将鼠标悬停在输入字段上时,右侧会出现滚动条。怎么避免这个?



<html>

<body>
  <div class="form-group">
    <br/>
    <label class="control-label">Hours spent :</label>
    <input type="number" id="hours" name="hours" placeholder="Please input total number of hours spent on this job." class="form-control">
  </div>
</body>

</html>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:2)

见下文

/* For Firefox */

input[type='number'] {
  -moz-appearance: textfield;
}


/* Webkit browsers like Safari and Chrome */

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
<html>

<body>
  <div class="form-group">
    <br/>
    <label class="control-label">Hours spent :</label>
    <input type="number" id="hours" name="hours" placeholder="Please input total number of hours spent on this job." class="form-control">
  </div>
</body>

</html>

答案 1 :(得分:1)

Grass

答案 2 :(得分:1)

我在thatstevensguy.com

上找到了这个解决方案

&#13;
&#13;
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
 
input[type="number"] {
    -moz-appearance: textfield;
}
&#13;
<html>

<body>
  <div class="form-group">
    <br/>
    <label class="control-label">Hours spent :</label>
    <input type="number" id="hours" name="hours" placeholder="Please input total number of hours spent on this job." class="form-control">
  </div>
</body>

</html>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

您可以使用CSS删除它们,假设您的意思是输入旋转器。

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
   -webkit-appearance: textfield; 
}

https://css-tricks.com/snippets/css/turn-off-number-input-spinners/