我在页面上有一个工作搜索框。目标是隐藏任何与当前搜索字符串不匹配的LI项目。但是,该列表是使用日历框架功能创建的,该功能还包含我想要查找的场所名称的同一行上的城市信息。标签内部HTML的jQuery过滤器
<script type="text/javascript">
$(document).ready(function()
{
$("#search").keyup(function()
{
// capture the current user search input, and create a RegEx for comparison
var searchString = $.trim(this.value);
var searchRegEx = new RegExp(searchString, "ig");
// Begin evaluating the user input once the 3rd character is inputted
if(searchString.length < 3)
{
// Otherwise make sure all records are displayed
$('li').show();
}
else
{
// Hide all of the records
$('li').hide();
// Filter a list of records that match RegEx from user input, and then display
$('li').filter(function()
{
return this.innerHTML.match(searchRegEx);
}).show();
}
});
});
</script>
这是绑定到INPUT TEXTBOX的函数调用。下面是我试图展示/隐藏的一个例子。
<ul>
<li><a href="http://somewebsite/path/index.php?com=location&lID=154">American Royal</a> | <span>Kansas City</span>
</li>
<li><a href="http://somewebsite/path/index.php?com=location&lID=155">Ameristar Casino Hotel Kansas City</a> | <span>Kansas City</span>
</li>
</ul>
'Ameri'应该显示两者,而'American'只返回一个值。这些搜索字符串有效;然而,如果有人输入“堪萨斯”,则显示的不是第2条记录。
我已经成功地捕获了A标签的HTML,但匹配(searchRegEx)似乎没有像我预期的那样工作。
我不明白,为什么你把网址,在那里或者这只是垃圾邮件?对不起,如果你是合法的! – simonmorley 2014-08-28 18:02:11
对于网址我很抱歉。我应该把它们拿出来。他们只是从复制粘贴。 – 2014-08-28 18:31:27