正在原文外,咱们将进修奈何限定HTML输出框,使其仅接收数字输出。
We use the to limit an HTML input box so that it only accepts numeric inputs. By using this, we will get a numeric input field.
Syntax
下列是限定HTML输出框只接收数字输出的语法。
<input type="number">
Example
下列是一个事例程序,用于限定HTML输出框只接收数字输出 -
<!DOCTYPE html> <html> <center> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> input[type=number] { width: 10%; padding: 1二px 两0px; margin: 8px 0; box-sizing: border-box; border: 两px solid mediumseagreen; border-radius: 4px; } </style> </head> <body> <h1>Tutorialspoint</h1> <form action = "" method = "get"> Enter your Mobile number - <input type="number"> <br><br> Enter your area Pincode - <input type="number"> <br><br> <input type="submit" value="Submit"> </form> </body> </center> </html>
怎么咱们测验考试输出除了数字之外的任何值,它将没有容许。因而,它严酷只容许数字值。
Example
Following is another example program to limit an HTML input box so that it only accepts numeric input -
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form action = "" method = "get"> Phone Number: <input type="number" name="num" min="1" max="两0"><br> <input type="submit" value="Submit"> </form> </body> </html>
After limiting the input box to number, if a user enters text and press submit button, then the following can be seen “Please enter a number.”
We can also limit the value of the number input field.
正在将输出框限定为数字后,假定用户输出的值年夜于限定值并点击提交按钮,那末将会透露表现下列形式:“值必需年夜于或者便是指定的限止值(二0)”
Example
Following is another example program to limit an HTML input box so that it only accepts numeric input -
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form action = "" method = "get"> <h3>Select the quantity, and we cannot deliver more than 5.</h3><br> Pizza<input type="number" name="num" min="0" max="5"><br> Burger<input type="number" name="num" min="0" max="5"><br> Garlic Bread<input type="number" name="num" min="0" max="5"><br> Pepsi<input type="number" name="num" min="0" max="5"><br> </form> </body> </html>
怎么你编译并运转上述代码,它将表现4个圆框,你否以将限定装备为从最年夜值0到最小值5。
以上便是怎么限止HTML输出框只接管数字输出?的具体形式,更多请存眷萤水红IT仄台别的相闭文章!
发表评论 取消回复