• <tfoot id='kE78E'></tfoot>
    • <bdo id='kE78E'></bdo><ul id='kE78E'></ul>

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

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

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

        如何防止在html中的数字字段中插入大于最大值的值

        时间:2023-06-13
          <bdo id='NNb5Q'></bdo><ul id='NNb5Q'></ul>

              <tbody id='NNb5Q'></tbody>

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

            • <i id='NNb5Q'><tr id='NNb5Q'><dt id='NNb5Q'><q id='NNb5Q'><span id='NNb5Q'><b id='NNb5Q'><form id='NNb5Q'><ins id='NNb5Q'></ins><ul id='NNb5Q'></ul><sub id='NNb5Q'></sub></form><legend id='NNb5Q'></legend><bdo id='NNb5Q'><pre id='NNb5Q'><center id='NNb5Q'></center></pre></bdo></b><th id='NNb5Q'></th></span></q></dt></tr></i><div id='NNb5Q'><tfoot id='NNb5Q'></tfoot><dl id='NNb5Q'><fieldset id='NNb5Q'></fieldset></dl></div>
                <tfoot id='NNb5Q'></tfoot>
              1. <legend id='NNb5Q'><style id='NNb5Q'><dir id='NNb5Q'><q id='NNb5Q'></q></dir></style></legend>
                1. 本文介绍了如何防止在html中的数字字段中插入大于最大值的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在html5中使用数字字段,

                  这是我的代码,

                  我使用 javascript 设置了这个数字字段的最大值.

                  element.max = 数量;元素.min = 0;element.step = 1;

                  如果我在数字字段中使用向上箭头.大于最大值的值是不可能的.但是当我尝试在该字段中插入时,可能会出现大于最大值的值.

                  我想阻止它.怎么样?

                  解决方案

                  就像你说的 number 类型的输入可以很好地使用箭头而不是手动更改,所以尝试使用 oninput 事件来帮助您控制用户输入:

                   document.getElementsByClassName('edit-items')[0].oninput = function () {var max = parseInt(this.max);if (parseInt(this.value) > max) {this.value = 最大值;}}

                  <input type="number" class="edit-items" max='10'/>

                  希望这会有所帮助.

                  I am using number field in html5,

                  here is my code,

                  <input type="number" class="edit-items" />
                  

                  i set the max of this number field using javascript.

                  element.max = quantity;
                  element.min = 0;
                  element.step = 1;
                  

                  If i am using the arrow-up in the number field. Greater value than the max is not possible. But when I tried to insert in the field, greater value than the max is possible.

                  I would like to prevent it. How?

                  解决方案

                  Like you said input of type number will work fine with arrows and not with manual change so try to use oninput event to help you control user inputs :

                      document.getElementsByClassName('edit-items')[0].oninput = function () {
                          var max = parseInt(this.max);
                  
                          if (parseInt(this.value) > max) {
                              this.value = max; 
                          }
                      }

                  <input type="number" class="edit-items" max='10'/>

                  Hope this helps.

                  这篇关于如何防止在html中的数字字段中插入大于最大值的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <legend id='ssJKE'><style id='ssJKE'><dir id='ssJKE'><q id='ssJKE'></q></dir></style></legend><tfoot id='ssJKE'></tfoot>

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

                            <tbody id='ssJKE'></tbody>