gpt4 book ai didi

jquery - 使用 jQuery 在每次输入按键时搜索列表项

转载 作者:太空宇宙 更新时间:2023-11-04 14:15:51 26 4
gpt4 key购买 nike

我正在尝试创建隐藏所有 <li> 的搜索功能其中 HTML 不等于 <input>值(value)。

我怎样才能用 jQuery 完成它?

$('input').keypress(function(){
if($('ul li').html != $('input').val()) {
$(this).hide();
}
});

最佳答案

你需要更多这样的东西:

$('input').keypress(function() {
var inputValue = $("input").val().toLowerCase();
$("li").each(function() {
if($(this).html().toLowerCase().indexOf(inputValue) == -1)
{
$(this).hide();
}
else
{
$(this).show();
}
});
});

关于jquery - 使用 jQuery 在每次输入按键时搜索列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26760162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com