简体   繁体   English

输入数字将最大值设置为十进制

[英]Input Number set max value to decimal

How to set html input type number, max value such that the max value is less than boundary (max) value not equal to boundary value? 如何设置HTML输入类型编号,最大值,以使最大值小于边界(max)值不等于边界值? Now what I can the do is as following but thats not the right solution because the list will go on 现在我可以做的是如下操作,但是那不是正确的解决方案,因为列表会继续

<input type="number" min="0" max="24" />

How to can I accept any value between 0 - 24 not 0 or 24 如何接受0-24之间的任何值,而不是0或24

<input type="number" min="0" max="23.9">

or 要么

<input type="number" min="0" max="23.99">

or 要么

<input type="number" min="0" max="23.999">

or 要么

<input type="number" min="0" max="23.999">

or 要么

<input type="number" min="0" max="23.9999">

I need to accept floating values, options other than regex 我需要接受浮点值,除正则表达式以外的选项

您可以给输入一个定义增量的步骤。

 <input type="number" min="0" max="23.99" step="0.01"> 

input number should not allow number to type more than the maximum value please check my below code it will help you for sure. 输入数字时,不允许输入的数字超过最大值,请检查我的以下代码,这将对您有所帮助。

 $("[type='number']").keypress(function (evt) { console.log(evt.key); var regex = /[0-9]/; if(regex.test(evt.key) ) { let value = parseInt($("[type='number']").val()+evt.key); console.log("value",value); value <= 24 ? "" : evt.preventDefault(); } else evt.preventDefault(); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="number" min="0" max="24" step="0.01"> 

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

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