ユーザーがタブを使用して必要な検索タイプを定義するjQuery検索スクリプトがあります。 $('#type_search').click();
を使用してタブがデフォルトとして選択されていますが、結果ページを更新するときに問題が発生します。別の検索タイプを選択してからページを更新すると、デフォルトのタブが自動的に選択されるため、ページURLが正しいと表示されても正しい結果が返されません。URLに基づいてデフォルトのjQueryタブを定義する
私の質問は、クエリがアクティブで、アクティブクエリがない場合は、デフォルトタブを使用する場合、URLのセクションからデフォルトタブを定義するにはどうすればよいですか?私はあなたが私の言っていることを理解できることを願っています。
私の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);
}
});
});
if (window.location.hash.indexOf('#' + type + '/') == 0) {
query = window.location.hash.replace('#' + type + '/', '').replace('/', '');
$('#query').val(decodeURIComponent(query)).keyup();
}
var textlength = $('#query').val().length;
if (textlength <= 0) {
$('#query').focus();
} else {
$('#query').blur();
}
});
回答が間違っていると思われる場合は、受け入れないでください。あなた自身の質問でモデレータにフラグを立てる必要はありません。 –