javascript - 如何取消 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>
解决方案
怎么样:
$("#clearButton").click(function(){
$("#listTeachers").find("li").show();
});
推荐阅读
- html - 在主屏幕上的 HTML 中获取按钮以路由到标有“关于”的页面
- django - Pyzipcode 城市查找无法正常工作
- mysql - 我正在尝试在 Debian 10 上安装 MySql 并不断收到错误消息。我究竟做错了什么?
- java - Palindrome String VarArgs - Java(没有数组只是 VarArgs)
- jekyll - 如何在 Github Pages 上修改 Jekyll 主题的 CSS / HTML?
- python - 将文本日期转换为年+月进行排序(即 1/19/2019 到 201901)
- tensorflow - LSTM(Keras)中样本步长和时间步长之间的差异
- php - 页面无法通过 GET 或 POST 请求访问我的 cookie
- python - 在python3中计算文本文件的单词
- python - 如何设置要在随机搜索中使用的指数分布的界限?