简体   繁体   中英

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? 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

<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"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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