实时文本搜索jquery,错误的选择器
Live text search jquery, wrong selector?
所以我对这个很陌生,请原谅我:)
这对我来说有点用,这是我的:
HTML:<form id="live-search" action="" class="styled" method="post">
<fieldset>
<input type="text" class="text-input" id="filter" value="" placeholder="Søg efter skole..." />
<span id="filter-count"></span>
</fieldset>
jQuery: $(document).ready(function(){
$("#filter").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the comment list
$(".ss_voting_manual .ss_voting_entry_list").find("li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Klasser fundet = "+count);
});
});
但是当我进行搜索时,它确实找到了li
,但是它失去了大部分的样式,如果你看到截图,它会更好地理解,然后我可以在书面上做
<div id="manual_voting" class="ss_voting_manual">
<ul class="ss_voting_entry_list">
<li class="my_db_entry item_handle_22924874" id="my_db_entry_22924874" style="">
<div class="entry_title entry_details">
<h4>Koge Handelsskole - 3C</h4>
</div>
<div class="entry_photo">
<ol>
<li style="display: list-item;"><img alt="" src=
"https://d2ndy3xguswqvu.cloudfront.net/images/220405/22924874/original_89bf1593506cabda8ec9fd63ac6e35d0.png"></li>
</ol>
</div>
<div class="entry_votes entry_details">
<span class="votes">65</span> Stemmer
</div>
<div class="entry_description entry_details ss_preserve_ws"></div>
<div class="itemActions entry_actions">
<ul>
<li class="item_vote" style="display: inline;"><a class="vote_link vote"
href="#" onclick=
"SST.vote_for(widget_14972805, 22924874, this); return false;">Stem</a></li>
<li class="item_share" style="display: inline;"><a class="share_link" href=
"#" onclick="ss_share(widget_14972805, 22924874); return false;">Del med dine
venner</a></li>
</ul>
</div>
<div class="clear"></div>
</li>
<li class="my_db_entry item_handle_22924821" id="my_db_entry_22924821" style=
"display: list-item;">
<div class="entry_title entry_details">
</div>
<div class="clear"></div>
</li>
</ul>
<div class="clear"></div>
<div class="ss_voting_paging" id="paging_voting"></div>
选择器错误
在您的目标代码中,您正在搜索.ss_voting_manual .ss_voting_entry_list
下的所有li
,包括孙子。
$(".ss_voting_manual .ss_voting_entry_list").find("li")
这将导致您的孙子li
's,包裹img
标签的人,被隐藏。
将选择器更改为只获取直系后代li
:
$(".ss_voting_manual .ss_voting_entry_list").children("li")
或
$(".ss_voting_manual .ss_voting_entry_list > li")
这将只获取ul
之后的第一个li
的直接集合。
相关文章:
- 文档就绪提供了错误的选择器高度
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- JavaScript类列表选择器错误
- 他们网站上的代码出现启动日期选择器错误
- jQuery选择器错误:无法识别的表达式
- 原型中漂亮的代码,如何省略'不是函数'空结果选择器上的错误
- 属性选择器不起作用(语法错误、无法识别的表达式)
- MVC4和日期选择器:“;0x800a01b6-JavaScript运行时错误:对象没有't支持属性或方法
- JQuery选择器理解错误
- jquery验证中生成的错误类的jquery选择器
- Jquery语法错误,id选择器上的表达式无法识别
- 未捕获错误:语法错误,无法识别表达式Jquery选择器单引号与双引号
- 选择id中带有双点的元素,错误:“#octo:cat”不是有效的选择器
- 错误:谷歌云端硬盘选择器今天停止加载
- 错误“属性'日期选择器'在带有打字稿的类型'IAugmentedJQuery'上不存在
- 角度材料的日期选择器日期错误
- 父后代 jquery 选择器中出现奇怪的错误
- 类型错误: $(..).日期选择器不是一个函数
- 角度 UI 日期选择器获取错误的日期
- j查询错误选择器上的点击功能