gpt4 book ai didi

jquery - 根据文本搜索显示 div

转载 作者:行者123 更新时间:2023-12-03 21:39:50 26 4
gpt4 key购买 nike

我有一个文本输入搜索,应该根据 div 的标题过滤 div。这是不起作用的代码:

$('.contact-name').each(function(){
var txt = $('#search-criteria').val();
$('this').find(txt).show()
});

我做错了什么?

编辑:澄清变量 txt 是用户在输入字段中键入的内容。一个例子是,如果 txt 是 Cha,我希望显示这一行:

<div class="contact-name"><h3><a href="##">Charles Smith</a></h3></div>

最佳答案

试试这个

var txt = $('#search-criteria').val();
$('.contact-name:contains("'+txt+'")').show();

<强> documentation for :contains() Selector

fiddle 示例:http://jsfiddle.net/WBvTj/2/

更新不区分大小写:

var txt = $('#search-criteria').val();
$('.contact-name').each(function(){
if($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1){
$(this).show();
}
});

fiddle 示例:http://jsfiddle.net/WBvTj/4/

关于jquery - 根据文本搜索显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9510064/

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