繁体   English   中英

如何将“类型=数字”限制为某些小数位

[英]How to restrict “type=number” to certain decimal places

我正在开发一个应用程序,在该应用程序中,我需要将提交的“类型=数量”数量限制为某些(2个地方)。 以下是element的HTML规则:请提供有人对此查询提供帮助,在此先感谢:

  <input type="number" name="amount" ng-model="orderStock.amount" class="form-control" id="amount" step="0.01" min="10" max="9999.99" placeholder=" Please enter Amount" ng-disabled="isDisabled" required /> 

您可以将输入事件侦听器附加到输入元素,并检查其值是否包含逗号。 如果是这样,请检查逗号右边是否有两个以上的字符,然后删除多余的字符。

 function process() { var text = document.getElementById("amount").value; var index = text.indexOf("."); if (index > -1) { if (text.length - index > 3) { document.getElementById("amount").value = text.substr(0, text.length - 1); } } } document.getElementById("amount").addEventListener("input", process); 
 <input type="number" name="amount" ng-model="orderStock.amount" class="form-control" id="amount" step="0.01" min="10" max="9999.99" placeholder=" Please enter Amount" ng-disabled="isDisabled" required /> 

如果要将所有代码都包含在html标记中,则可以执行以下操作:

 <input type="number" name="amount" ng-model="orderStock.amount" class="form-control" id="amount" step="0.01" min="10" max="9999.99" oninput="var text = this.value;var index = text.indexOf('.');if (index > -1) {if (text.length - index > 3) {this.value = text.substr(0, text.length - 1);}}" placeholder=" Please enter Amount" ng-disabled="isDisabled" required /> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM