仅在页面刷新时才记住复选框

时间:2019-12-20 11:13:44

标签: javascript checkbox turbolinks

我有一个带有复选框的页面。如果我检查了其中的一些并返回,则当我返回带有链接的页面时,该复选框未选中;如果此时刷新页面,则我先前选中的复选框会再次被选中。我没有JavaScript来管理此行为,仅启用了Turbolinks。为什么会这样?如何从一开始就还原复选框?

<!doctype html>
<html lang="en">

<head>
  <link rel='icon' href='favicon.ico' type='image/x-icon' />

  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="style/css/bootstrap.min.css">
  <link rel="stylesheet" href="style/css/style.css" type="text/css">

  <script src="https://kit.fontawesome.com/e5f3028323.js" crossorigin="anonymous"></script>

  <!-- JavaScript -->
  <script type="text/javascript" src="/js/turbolinks.js"></script>

  <script type="text/javascript" src="/js/js.cookie.js"></script>

  <title>App</title>
</head>

<body>

  <section id="setup-game" class="container">
    <div class="row">
      <div class="col text-center">
        <div class="list-checkbox list-group list-button mx-auto mt-2">
          <label class="list-group-item d-flex justify-content-between align-items-center pointer-cursor">
            <input class="checkbox-cw" type="checkbox">
          </label>
          <label class="list-group-item d-flex justify-content-between align-items-center pointer-cursor">
            <input class="checkbox-cw" type="checkbox">
          </label>
          <label class="list-group-item d-flex justify-content-between align-items-center pointer-cursor">
            <input class="checkbox-cw" type="checkbox">
          </label>
          <label class="list-group-item d-flex justify-content-between align-items-center pointer-cursor">
            <input class="checkbox-cw" type="checkbox">
          </label>
          <label class="list-group-item d-flex justify-content-between align-items-center pointer-cursor">
            <input class="checkbox-cw" type="checkbox">
          </label>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col text-center mb-3">
        <button type="button" class="btn-largo" onclick="keepTrack();">Track Game</button>
      </div>
    </div>
  </section>

  <!-- JavaScript -->
  <script type="text/javascript" src="js/bootstrap-native-v4.min.js"></script>
  <script type="text/javascript" src="js/script.js"></script>
</body>

</html>

0 个答案:

没有答案