使用contains()进行页内搜索以显示/隐藏div内容
我正在尝试在我的常见问题解答页面添加搜索function,我绝对卡住了。
我想要的是一个文本框,用户输入一个关键字(或多个单词),为关键字运行jquery,并为所有相关答案设置display:block。
到目前为止我所拥有的是:
This is the first software question and answer. This is the first hardware question and answer. function searchFunction() { var searchTerm = document.searchBox.keyword.value; $(" :contains('"+searchTerm+"')").addStyle("display:block"); }
试试这个
function searchFunction() { var searchTerm = document.searchBox.keyword.value; $(".searchable").each(function(){ $(this).(":contains('"+searchTerm+"')").show(); }); }
试试这个。
function searchFunction() { $(".searchable") .hide() .filter(":contains('" + $("input[name='keyword']").val() + "')") .show(); }
将.addStyle(“display:block”)更改为.show()