【发布时间】:2013-03-26 09:57:27
【问题描述】:
我使用 jQuery 从头开始编写了一个搜索功能,以满足特定需求。它从<div> 的<span> 中搜索数据,然后在与文本框中的字符串不匹配时隐藏<div>。
我遇到的问题是它会识别字符串但不能识别第一个字符。它也区分大小写,这不是我想要包含的功能。
//Grab ID of current recordContainer
var currentID = $(this).attr('id');
// Add hash tag so it can be used as an ID call
var currentID2 = ("#" + currentID);
//Grab data from author span in current recordContainer
var currentAuthor = $(this).children('span.listLeadAuthor').text();
//If current author matches anything in the search box then keep it visible
if (currentAuthor.search(searchBox1) > 0)
{
$(currentID2).show();
count++;
}
//If search box is empty keep it visible
else if (searchBox1 === "")
{
$(currentID2).show();
}
【问题讨论】:
-
请复制粘贴问题中的代码。
-
currentAuthor.search(searchBox1) !== -1
标签: javascript jquery search