我们知道 HTML5 中的 input 标签支持 number 的类型,支持只能输入数字:
1 |
<pre class="inline:true class:language-markup decode:1 " ><span class="token tag"><span class="token punctuation"><</span>input <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span>"number"</span> <span class="token punctuation">/></span></span> |
如果我们的业务需求中要求输入浮点数怎么实现呢?其实可以通过 step 属性来实现,step 属性默认值是 1,如果将 step 定义成 0.01,即可实现浮点数的输入:
1 |
<pre class="inline:true class:language-markup decode:1 " ><span class="token tag"><span class="token punctuation"><</span>input <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span>"number"</span> <span class="token attr-name">step</span><span class="token attr-value"><span class="token punctuation">=</span>"0.01"</span> <span class="token punctuation">/></span></span> |
记录一下,以前以为 input type=”number” 只支持输入整数,没想到也支持浮点数,并且还那么简单。 ?
浏览量: 11