我已经使用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();
}
请复制粘贴问题中的代码。 – JJJ 2013-03-26 09:59:07
'currentAuthor.search(searchBox1)!== -1' – 2013-03-26 10:04:48