• <tfoot id='D4iGP'></tfoot>

    <i id='D4iGP'><tr id='D4iGP'><dt id='D4iGP'><q id='D4iGP'><span id='D4iGP'><b id='D4iGP'><form id='D4iGP'><ins id='D4iGP'></ins><ul id='D4iGP'></ul><sub id='D4iGP'></sub></form><legend id='D4iGP'></legend><bdo id='D4iGP'><pre id='D4iGP'><center id='D4iGP'></center></pre></bdo></b><th id='D4iGP'></th></span></q></dt></tr></i><div id='D4iGP'><tfoot id='D4iGP'></tfoot><dl id='D4iGP'><fieldset id='D4iGP'></fieldset></dl></div>
        <bdo id='D4iGP'></bdo><ul id='D4iGP'></ul>

        <small id='D4iGP'></small><noframes id='D4iGP'>

        <legend id='D4iGP'><style id='D4iGP'><dir id='D4iGP'><q id='D4iGP'></q></dir></style></legend>

        在&lt;input type=“number"&gt;中允许2位小数

        时间:2023-10-12

        <i id='ihYmr'><tr id='ihYmr'><dt id='ihYmr'><q id='ihYmr'><span id='ihYmr'><b id='ihYmr'><form id='ihYmr'><ins id='ihYmr'></ins><ul id='ihYmr'></ul><sub id='ihYmr'></sub></form><legend id='ihYmr'></legend><bdo id='ihYmr'><pre id='ihYmr'><center id='ihYmr'></center></pre></bdo></b><th id='ihYmr'></th></span></q></dt></tr></i><div id='ihYmr'><tfoot id='ihYmr'></tfoot><dl id='ihYmr'><fieldset id='ihYmr'></fieldset></dl></div>

          <small id='ihYmr'></small><noframes id='ihYmr'>

            <bdo id='ihYmr'></bdo><ul id='ihYmr'></ul>
            <legend id='ihYmr'><style id='ihYmr'><dir id='ihYmr'><q id='ihYmr'></q></dir></style></legend>
          • <tfoot id='ihYmr'></tfoot>

                  <tbody id='ihYmr'></tbody>
                1. 本文介绍了在&lt;input type=“number"&gt;中允许2位小数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 <input type="number">,我想将用户的输入限制为纯数字或小数点后两位小数.

                  I have a <input type="number"> and I want to restrict the input of the users to purely numbers or numbers with decimals up to 2 decimal places.

                  基本上,我要求输入价格.

                  Basically, I am asking for a price input.

                  我想避免使用正则表达式.有办法吗?

                  I wanted to avoid doing regex. Is there a way to do it?

                  <input type="number" required name="price" min="0" value="0" step="any">
                  

                  推荐答案

                  step="any" 允许任意位数的小数,使用 step=".01",最多允许两位小数.

                  Instead of step="any", which allows for any number of decimal places, use step=".01", which allows up to two decimal places.

                  规范中的更多详细信息:https://www.w3.org/TR/html/sec-forms.html#the-step-attribute

                  More details in the spec: https://www.w3.org/TR/html/sec-forms.html#the-step-attribute

                  这篇关于在&lt;input type=“number"&gt;中允许2位小数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:测试一个值是奇数还是偶数 下一篇:JavaScript 字符串和数字转换

                  相关文章

                  最新文章

                  <legend id='Ft4k5'><style id='Ft4k5'><dir id='Ft4k5'><q id='Ft4k5'></q></dir></style></legend>

                      <small id='Ft4k5'></small><noframes id='Ft4k5'>

                      <tfoot id='Ft4k5'></tfoot>
                      <i id='Ft4k5'><tr id='Ft4k5'><dt id='Ft4k5'><q id='Ft4k5'><span id='Ft4k5'><b id='Ft4k5'><form id='Ft4k5'><ins id='Ft4k5'></ins><ul id='Ft4k5'></ul><sub id='Ft4k5'></sub></form><legend id='Ft4k5'></legend><bdo id='Ft4k5'><pre id='Ft4k5'><center id='Ft4k5'></center></pre></bdo></b><th id='Ft4k5'></th></span></q></dt></tr></i><div id='Ft4k5'><tfoot id='Ft4k5'></tfoot><dl id='Ft4k5'><fieldset id='Ft4k5'></fieldset></dl></div>
                      • <bdo id='Ft4k5'></bdo><ul id='Ft4k5'></ul>