Bootstrap5 选择区间

2023-07-11 15:14 更新

要设置一个选择区间可以在 input 元素中添加 type="range" 并使用 .form-range 类:

选择区间:


<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" 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>选择区间</h2>
  <p>要设置一个选择区间可以在 input 元素中添加 type="range" 并使用 .form-range 类:</p>
  <form action="/action_page.php">
    <label for="customRange" class="form-label">自定义选择区间</label>
    <input type="range" class="form-range" id="customRange" name="points">
    <label for="customRange" class="form-label">默认选择区间</label>
    <input type="range" id="defaultRange" name="points"><br>
    <button type="submit" class="btn btn-primary mt-3">Submit</button>
  </form>
</div>

</body>
</html>

步长

默认情况下,步长为 1,可以通过 step 属性来设置:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" 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>选择区间步长</h2>
  <p>默认情况下,步长为 1,可以通过 step 属性来设置:</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>

最大最小值

默认情况下,最小值为 0,最大值为 100,可以通过 min(最小) 或 max(最大) 属性来设置:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap5 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" 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>选择区间最大最小值</h2>
  <p>默认情况下,最小值为 0,最大值为 100,可以通过 min(最小) 或 max(最大) 属性来设置:</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>


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号