我已經使用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