私は、ユーザが使用する検索タイプを定義するためのタブを使用するjQuery検索スクリプトを用意しています。ユーザーが検索すると、#タイプ/クエリ /のようなURLが作成されます。ただし、ページをリロードすると、別のページに移動した結果をクリックするか、検索結果が表示されなくなった前のページから戻ることができます。なぜこれができ、私はこの問題をどうやって解決できますか?私はいずれのプラグインも使いたくない。URLからjQueryを使用して動的divコンテンツをロードする
私のjQueryのコードは次のとおりです。
$(document).ready(function() {
$('[id^=type_]').click(function() {
type = this.id.replace('type_', '');
$('[id^=type_]').removeClass('selected');
$('#type_' + type).addClass('selected');
return false;
});
$('#type_search').click();
$('#query').keyup(function() {
var query = $(this).val();
var url = '/' + type + '/' + query + '/';
window.location.hash = '' + type + '/' + query + '/';
document.title = $(this).val() + ' - My Search';
$('#results').show();
if (query == '') {
window.location.hash = '';
document.title = 'My Search';
$('#results').hide();
}
$.ajax({
type: 'GET',
url: url,
dataType: 'html',
success: function (results) {
$('#results').html(results);
}
});
});
var textlength = $('#query').val().length;
if (textlength <= 0) {
$('#query').focus();
} else {
$('#query').blur();
}
});
セットアップルーチンの後ろにコードを配置してください。 – marc