Bootstrap5 選擇區(qū)間

2023-07-11 15:14 更新

要設(shè)置一個(gè)選擇區(qū)間可以在 input 元素中添加 type="range" 并使用 .form-range 類:

選擇區(qū)間:


<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 實(shí)例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
  <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
</head>
<body>

<div class="container mt-3">
  <h2>選擇區(qū)間</h2>
  <p>要設(shè)置一個(gè)選擇區(qū)間可以在 input 元素中添加 type="range" 并使用 .form-range 類:</p>
  <form action="/action_page.php">
    <label for="customRange" class="form-label">自定義選擇區(qū)間</label>
    <input type="range" class="form-range" id="customRange" name="points">
    <label for="customRange" class="form-label">默認(rèn)選擇區(qū)間</label>
    <input type="range" id="defaultRange" name="points"><br>
    <button type="submit" class="btn btn-primary mt-3">Submit</button>
  </form>
</div>

</body>
</html>

步長

默認(rèn)情況下,步長為 1,可以通過 step 屬性來設(shè)置:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 實(shí)例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
  <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
</head>
<body>

<div class="container mt-3">
  <h2>選擇區(qū)間步長</h2>
  <p>默認(rèn)情況下,步長為 1,可以通過 step 屬性來設(shè)置:</p>
  <form action="/action_page.php">
    <label for="customRange" class="form-label">自定義步長</label>
    <input type="range" class="form-range" step="10">
    <button type="submit" class="btn btn-primary mt-3">Submit</button>
  </form>
</div>

</body>
</html>

最大最小值

默認(rèn)情況下,最小值為 0,最大值為 100,可以通過 min(最?。?或 max(最大) 屬性來設(shè)置:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 實(shí)例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="external nofollow" target="_blank"  rel="stylesheet">
  <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ></script>
</head>
<body>

<div class="container mt-3">
  <h2>選擇區(qū)間最大最小值</h2>
  <p>默認(rèn)情況下,最小值為 0,最大值為 100,可以通過 min(最?。?或 max(最大) 屬性來設(shè)置:</p>
  <form action="/action_page.php">
    <label for="customRange" class="form-label">自定義步長</label>
    <input type="range" class="form-range" min="0" max="4">
    <button type="submit" class="btn btn-primary mt-3">Submit</button>
  </form>
</div>

</body>
</html>


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號