我試圖用Javascript創建搜索功能,但它不起作用。使用JavaScript在HTML中搜索功能
function contains(text_one, text_two) {
if (text_one.indexof(text_two) != -1)
return true;
}
$("#searchText").onkeyup(function(){
var searchText = $("searchText").val().toLowerCase()
$("ul li").each(function() {
if (!contains($(this).text().toLowerCase(), searchText))
$(this).hide();
else
$(this).show();
});
});
請給我們您的HTML,CSS(如果有的話),和JavaScript。還要告訴你,你想要達到什麼目標,哪些不起作用。 –