0
我有一個jQuery搜索腳本,它爲用戶使用選項卡來定義他們想要使用的搜索類型。但是,當用戶搜索某物然後選擇一種新的搜索類型(單擊一個選項卡)時,他們必須轉到文本框並按Enter鍵以再次提交查詢。在選項卡上調用jQuery搜索點擊
我想在用戶點擊自己選擇的標籤時調用搜索,而不必重新提交查詢。我該怎麼做?我希望你能理解我想要描述的東西。
我當前的jQuery代碼是:
$(document).ready(function(){
$("[id^=t_]").click(function(){
t=this.id.replace("t_","");
$("[id^=t_]").removeClass("s");
$("#t_"+t).addClass("s");
return false
});
$("#t_search").click();
$("form").submit(function(event){
event.preventDefault();
if($("#s").val().length>0){
q=$("#s").val();
$.ajax({
type:"GET",
url:""+t+".php?q="+q,
dataType:"html",
success:function(c){
$("#r").html(c);
$("#r").show()
}
});
}
});
});
我當前的HTML代碼:
<div id="n">
<a href="/" id="t_search" class="s">All</a>
<a href="/images" id="t_images">Images</a>
<a href="/videos" id="t_videos">Videos</a>
<a href="/news" id="t_news">News</a>
</div>
<form action="search" method="get">
<input type="text" id="s" name="q" maxlength="2048" autocomplete="off">
</form>
<div id="r"></div>