我使用 jQuery 从头开始编写了一个搜索功能,以满足特定需求。<span>
它从a 中搜索数据,然后如果它与文本框中的字符串不匹配<div>
,则隐藏它。<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();
}