0
我有查詢一個PHP文件,然後把結果解析成HTML DIV一個谷歌即時風格的jQuery搜索腳本。它使用用戶定義的標籤來定義他們想要使用的搜索類型。當用戶搜索,創建一個URL這是像#型/查詢 /。分頁jQuery的搜索結果
我的問題是,當一些用戶的搜索,然後(在選項卡上點擊)選擇一個新的搜索類型,他們必須去到文本框,然後按回車再次提交其查詢。我怎樣才能使它所以當搜索是積極的,並在單擊選項卡,它加載結果馬上呢?
我希望你能理解我想要描述的東西。的jsfiddle:http://jsfiddle.net/phWSR/
我當前的jQuery代碼是:
$(document).ready(function() {
$('[id^=type_]').click(function() {
type = this.id.replace('type_', '');
$('[id^=type_]').removeClass('selected');
$('#type_' + type).addClass('selected');
});
$('#type_search').click();
$('input').keyup(function() {
query = $(this).val();
url = '/' + type + '/' + query + '/';
window.location.hash = '' + type + '/' + query + '/';
document.title = $(this).val() + ' - My Search Script';
$('#results').show();
if (query == '') {
window.location.hash = '';
document.title = 'My Search Script';
$('#results').hide();
}
$.ajax({
type: 'GET',
url: url,
dataType: 'html',
success: function (results) {
$('#results').html(results);
}
});
});
});
我當前的HTML代碼:
<div id='nav'>
<a id='type_search'>All</a>
<a id='type_images'>Images</a>
<a id='type_videos'>Videos</a>
<a id='type_news'>News</a>
<a id='type_social'>Social</a>
</div>
<input type='text' autocomplete='off'>
<div id='results'></div>