首页 > 解决方案 > 如何取消 JS 函数?

问题描述

我目前正在尝试创建一个功能正常的过滤器按钮。下面的脚本允许我根据选择的过滤器选项过滤列表。

我想包括一个清除按钮,清除应用的过滤器。最好是取消相应的功能。

有没有办法做到这一点?

谢谢。

$('#filterLevel').change(function(){
  var level = $(this).val();
  $("#listTeachers").find("li").hide()
      $.each($("#listTeachers").find("li"),function(){
          if($(this).data('filtertext')==level)
              $(this).show();

      });
});            
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Filter Panel - County Job Filter -->
<div data-role="panel" id="schoolfilterPanel" data-display="overlay" data-position="left">
    <form id="filterJobs">
    <p class="filterHeader">FILTER</p>
    <h1 class="filterCountyHeader">Teaching Level:</h1>
        <select id="filterLevel" onchange='filterLevel()'><option disabled selected>Select level...</option><option value="Primary">Primary School</option><option value="Secondary">Secondary School</option></select><br>
    </form>
    <button id="clearButton">CLEAR</button>
    </div>
</div>

标签: javascripthtml

解决方案


怎么样:

$("#clearButton").click(function(){
 $("#listTeachers").find("li").show();
});

推荐阅读