我想创建一个按钮,以重置页面上的所有过滤器。啤酒Eventlistery。
我有几个广播按钮。我有一个可以按价格,尺寸和颜色隔离的项目列表(单击"单击单击"按钮)。
当我单击按钮(重置按钮)时,我希望过滤器删除,然后将项目返回其位置。
这是我的代码
function stop() {
Array.from(document.querySelectorAll('.choice--radio')).map(x => x.removeEventListener("click", sortNumber));
Array.from(document.querySelectorAll('.choice--radio')).map(x => x.checked = false);
}
clear.addEventListener('click', stop);
html代码
<ul class="sort__options">
<li>
<input class="choice choice--radio" name="sort" type="radio" id="sort-title">
<label class="choice__label" for="sort-title">title</label>
</li>
<li>
<input class="choice choice--radio" name="sort" type="radio" id="sort-subscribers">
<label class="choice__label" for="sort-subscribers">subscribers</label>
</li>
<li>
<input class="choice choice--radio" name="sort" type="radio" id="sort-videos">
<label class="choice__label" for="sort-videos">videos</label>
</li>
<li>
<input class="choice choice--radio" name="sort" type="radio" id="sort-views">
<label class="choice__label" for="sort-views">views</label>
</li>
</ul>
我正在删除检查属性。但是这些元素没有返回其原始位置,它们是按照他们对此事件进行分类的顺序。
如何解决此问题?
您可以轻松地使用
的Form reset()
方法 document.getElementById("myForm").reset();
尝试以下内容:
<input type="button" onclick="myFunction()" value="Reset Button">
然后继续将脚本声明为:
<script>
function myFunction() {
document.getElementById("myForm").reset();
}
</script>
请尝试。