では早速質問です!
検索ボックスに「 orange 」または「 apple」と入力すると、そうでないものが非表示になっていることがわかります。
それは完璧に機能します。
私がやろうとしているのは、たとえばorangeをクリックすると、その検索ボックスに入力してから、自然にオレンジを入力したときに何をするかということです..
現在、オレンジ色をクリックすると検索ボックスがいっぱいになりますが、jquery は機能しません。
アイデアや助けはありますか?
HTML
Search: <input id = "searchbox" type = "text"/><br/>
<div class="track">
<h1>Section 1</h1>
<h3><a style="cursor:pointer;" onclick="document.getElementById('searchbox').value='orange';">orange</a></h3>
</div>
<div class="track">
<h1>section 2</h1>
<h3><a style="cursor:pointer;" onclick="document.getElementById('searchbox').value='apple';">apple</a></h3>
</div>
Jクエリ
$("#searchbox").on("keydown keyup keypress change", function() {
var query = this.value.toLowerCase();
$(".track").each(function() {
var cur = $(this);
if(cur.text().toLowerCase().indexOf(query) == -1) {
cur.hide("fast");
}
else {
cur.show("fast");
}
});
});