ページが変更されたため、スクリプトが再度読み込まれます。あなたはあなたが持っているURLをテストする必要があります
さまざまなorderby値を処理するように更新されました
$(document).ready(function() {
$('.orderby').click(
function(){
var srch = location.search;
if (srch) srch = srch.substring(1); // lose the ?
var val = $(this).val();
if (srch.indexOf(val+"ASC")!=-1)
srch = srch.replace(val+"ASC",val+"DESC");
else if (srch.indexOf(val+"DESC")!=-1)
srch = srch.replace(val+"DESC",val+"ASC");
else if (!srch || srch.indexOf("orderby")!=-1) {
// if srch was empty or contained another value than this'
srch ='orderby='+$(this).val()+'ASC';
}
var loc = (location.search)?location.href.split("?")[0]:location.href;
window.location = loc + "?"+srch;
});
});
PS:document.location.hrefは何年も前に非推奨になりました。代わりにdocument.URLまたはwindow.location.hrefを使用してください
PPS:MilkyWayJoeが正しく述べているように(なぜわざわざ)、ページがサーバーから現在のページに読み込まれ、iframeやajaxされていない場合は、サーバーのボタンの値を設定し、通常のリンクを設定します。 JSがオフの場合でも動作します
UPDATE2
AJAXを使用する場合は、次のようなことを行います。
$(document).ready(function() {
if (location.hash.indexOf(....) {
// find the element which is mentioned in the orderby and click it
var $elem = ....
$elem.click(); // or trigger
}
$('.orderby').toggle(
function(){
$("#someLabel").html("DESC");
var orderBy = $(this).val()+'ASC';
location.hash = orderBy; // now URL will be ...#nameASC
$("#content").load('soneserverprocess?orderby='+orderBy);
},
function(){
$("#someLabel").html("ASC");
var orderBy = $(this).val()+'DESC';
location.hash = orderBy; // now URL will be ...#nameDESC
$("#content").load('someserverprocess?orderby='+orderBy);
});
});
ブラウザ内の並べ替えを使用する場合は、次のいずれかを使用してください
http://www.tripwiremagazine.com/2012/02/jquery-filter-sort-plugins.html
と持っている
$(document).ready(function() {
if (location.hash.indexOf(....) {
// find the element which is mentioned in the orderby and click it
var $elem = ....
$elem.click(); // or trigger
}
$('.orderby').toggle(
function(){
$("#someLabel").html("DESC");
var orderBy = $(this).val()+'ASC';
location.hash = orderBy; // now URL will be ...#nameASC
$("#content").sort(....); // depending on plugin
},
function(){
$("#someLabel").html("ASC");
var orderBy = $(this).val()+'DESC';
location.hash = orderBy; // now URL will be ...#nameDESC
$("#content").sort(....); // depending on plugin
});
});