HTMLmax 屬性


<input>元素的 max 屬性用於設定 <input>的最大值。min 和 max 均用於設定型別為 number、date、datetime、range 等等的 input 元素的值範圍,並在 HTML5 中引入。

現在讓我們看一個實施 <input> 元素的 man 屬性的示例。在此,我們設定 max 為 10,因此使用者不能輸入超過 1 的 ID −

示例

 動態演示

<!DOCTYPE html>
<html>
<body>
<h2>Log in to your account</h2>
<form action="" method="get">
   Id − <input type="number" name="id" min="1" max="10"><br>
   Password − <input type="password" name="pwd"><br>
   DOB − <input type="date" name="dob" autofocus><br>
   <button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>

輸出

在上面的示例中,我們建立了一個具有某些欄位和按鈕的表單 −

<form action="" method="get">
   Id − <input type="number" name="id" min="1" max="10"><br>
   Password − <input type="password" name="pwd"><br>
   DOB − <input type="date" name="dob" autofocus><br>
   <button type="submit" value="Submit">Submit</button>
</form>

對 id 輸入型別 number 設定 max 屬性。max 值設定為 10,因此使用者不能輸入超過 10 的值 −

Id − <input type="number" name="id" min="1" max="10">

更新於:30-Jul-2019

298 次瀏覽

開啟您 職業生涯

透過完成課程取得認證

開始
廣告
© . All rights reserved.