admin管理员组文章数量:1287811
I am trying to add a search functionality to my FAQ page and am absolutely stuck.
What I want is a text box where the user inputs a keyword(or words), that runs a jquery for the keyword and sets display:block for all the relevant answers.
What I have so far is this:
<form name="searchBox">
Keyword(s): <input type="text" name="keyword" />
<input type="button" value="Search" onClick="searchFunction()" />
</form>
<div class="searchable" style="display:none">
This is the first software question and answer.</div>
<div class="searchable" style="display:none">
This is the first hardware question and answer.</div>
<script type="text/javascript">
function searchFunction() {
var searchTerm = document.searchBox.keyword.value;
$(" :contains('"+searchTerm+"')").addStyle("display:block"); }
</script>
I am trying to add a search functionality to my FAQ page and am absolutely stuck.
What I want is a text box where the user inputs a keyword(or words), that runs a jquery for the keyword and sets display:block for all the relevant answers.
What I have so far is this:
<form name="searchBox">
Keyword(s): <input type="text" name="keyword" />
<input type="button" value="Search" onClick="searchFunction()" />
</form>
<div class="searchable" style="display:none">
This is the first software question and answer.</div>
<div class="searchable" style="display:none">
This is the first hardware question and answer.</div>
<script type="text/javascript">
function searchFunction() {
var searchTerm = document.searchBox.keyword.value;
$(" :contains('"+searchTerm+"')").addStyle("display:block"); }
</script>
Share
Improve this question
asked Jul 15, 2011 at 15:47
FrazzleSnazzleFrazzleSnazzle
431 silver badge3 bronze badges
2
-
What is the value of
searchTerm
? – George Cummins Commented Jul 15, 2011 at 15:49 - Please elaborate on why this isn't working. – a'r Commented Jul 15, 2011 at 15:49
3 Answers
Reset to default 7Try this
function searchFunction() {
var searchTerm = document.searchBox.keyword.value;
$(".searchable").each(function(){
$(this).(":contains('"+searchTerm+"')").show();
});
}
Try this.
function searchFunction() {
$(".searchable")
.hide()
.filter(":contains('" + $("input[name='keyword']").val() + "')")
.show();
}
Change .addStyle("display:block") to .show()
本文标签: javascriptInpage search using contains() to showhide div contentStack Overflow
版权声明:本文标题:javascript - In-page search using contains() to showhide div content - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741326689a2372525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论