页面重新加载时保存选中的复选框 [英] save checked checkboxes when Page reloads

查看:86
本文介绍了页面重新加载时保存选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的搜索引擎,我使用带有复选框的表单设计了一个过滤器。提交这些文件时,过滤器功能可以正常工作(为此使用Flask)。显示结果时,将再次取消选中用作过滤器的复选框。我是否需要将信息保存在localStorage中,该怎么做?
感谢您的帮助< 3

For my search-engine I designed a filter using a form with checkboxes. When submitting those, the filter function works fine (using Flask for this). Yet the checkboxes which where used as a filter are unchecked again when the results are shown. Do I need to save the information in the localStorage, and how can this be done? Thanks for your help <3

这是我的复选框代码的一部分(我是HTML / JS的新手):

This is a part of my Code for the checkbox (I am a newbie to HTML/JS):

 <form>                  
  <article class="card-group-item">                      
    <header class="card-header">                          
      <span class="title">Document Types </span>               
    </header>                     
      <div class="filter-content">
          <div class="card-body">
             <label class="form-check" >
                 <input class="form-check-input" type="checkbox" name="doctype" value="offer" id="offer">
                 <span class="form-check-label">Offer</span>
             </label> <!-- form-check.// -->
             <button type="submit" class="btn btn-secondary btn-sm">Submit</button>
          </div> <!-- card-body.// -->
      </div>
   </article> <!-- card-group-item.// -->
 </form>

推荐答案

在复选框中使用已选中,并在此处

Use checked in your checkbox and read here

 <form>                  
  <article class="card-group-item">                      
    <header class="card-header">                          
      <span class="title">Document Types </span>               
    </header>                     
      <div class="filter-content">
          <div class="card-body">
             <label class="form-check" >
                 <input class="form-check-input" type="checkbox" name="doctype" value="offer" id="offer" checked>
                 <span class="form-check-label">Offer</span>
             </label> <!-- form-check.// -->
             <button type="submit" class="btn btn-secondary btn-sm">Submit</button>
          </div> <!-- card-body.// -->
      </div>
   </article> <!-- card-group-item.// -->
 </form>

这篇关于页面重新加载时保存选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆