我正在处理下面的代码。我正在尝试筛选并获取包含类似输入字符串的项目项的索引和值,但它不起作用。
var items =[ {item:"Saab", sku:"SA"},
{item:"Volvo", sku:"VO"},
{item:"BMW", sku:"BM"},
{item:"Toyota", sku:"TO"},
{item:"Honda", sku:"HO"},
{item:"Nissan", sku:"NI"},
];
$("#filter").keyup(function () {
var filter = $(this).val();
$(items['item']).each(function (index, value) {
if (value.search(new RegExp(filter, "i")) < 0) {
// Do somethign
} else {
console.log(index);
console.log(value);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="live-search" action="" class="styled" method="post">
<fieldset>
<input type="text" class="text-input" id="filter" value="" />
<span id="filter-count"></span>
</fieldset>
</form>
吃鸡游戏
郎朗坤
慕沐林林
慕哥6287543
相关分类