【发布时间】:2021-07-09 18:32:13
【问题描述】:
我想问是否有人知道如何解决我的问题。过滤适用于其他所有(我想不区分大小写),但在搜索“食物”后不会出现复选框。我需要创建一个带有复选框的类别列表。如果您搜索一个类别,您可以立即选中复选框
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myDIV *").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
</head>
<body>
<h2>Filter</h2>
<!--Type something in the input field to search for a specific text inside the div element with id="myDIV" -->
<input id="myInput" type="text" placeholder="Search..">
<div id="myDIV">
<p>dog</p>
<div>master20</div>
<button>Button</button>
<p>Welcome5</p>
<label class="important_class_for_me">Food
<input type="checkbox">
<span class="my_custom_checkmark"></span>
</label>
</div>
</body>
</html>
【问题讨论】:
-
那种非常松散的结构不太利于你想做的事情。
标签: javascript html jquery checkbox filter