2011-08-03 26 views
0

我添加了幾個新頁面,並在左側包含了菜單框,標題爲left_menu.php。然而,當從2個新頁面中點擊類別標題時,我不會被髮送到正確的類別或任何類別。Window.location Java Script/JQuery/PHP問題

我已經包含J /查詢JavaScript代碼,仍然沒有喜悅。我注意到window.location被設置爲window.location.hash =(後面跟着查詢字符串),但這隻適用於具有菜單/categories.php的原始頁面。一個例子是http://isenterprises.co.uk/category#3:any:any:1:'3'是該類別。

在我的兩個新頁面/search_results.php和/singleproduct.php,/ search_results?#3:any:any:1:和/singleproduct.php?#3:any:any:1:不起作用。我試過,window.location window.location.href(「/categories.php」)=(後面跟着查詢字符串)。但是這也行不通。

有沒有一種方法,使2個新頁面顯示通過簡單地改變window.location的目的地或可有人請拿出一個簡單的選擇所需要的結果嗎?我已經包含了下面的腳本。

一個

<script type="text/javascript"> 
(function($) { 
$.fn.stripHtml = function() { 
    var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi; 
    this.each(function() { 
     $(this).html( 
      $(this).html().replace(regexp,"") 
     ); 
    }); 
    return $(this); 
} 
})(jQuery); 
$(function(){ 
$.preloadImages = function() 
{ 
    for(var i = 0; i<arguments.length; i++) 
    { 
    jQuery("<img>").attr("src", arguments[i]); 
    } 
} 
$.preloadImages("/images/loading.gif"); 
var sProduct = ""; 
var sBrand = ""; 
var sCategory = ""; 
var sPage = ""; 
var sSearch = ""; 
var split_address = Array; 
split_address[0] = "any"; 
split_address[1] = "any"; 
split_address[2] = "any"; 
split_address[3] = 1; 
split_address[4] = ""; 
var address = window.location.hash; 
if (address != "") 
{ 

     address = address.replace(/^#*/i, ""); 
     address = address.replace(/%20/g, " "); 
     split_address = address.split(":"); 
// Call other function here and send it the inputs inside the split_address array 
} 
if ((split_address[0] != "" && split_address[1] != "" &&            split_address[2]                         !=    || split_address[4] != "") { 
    sProduct = split_address[0]; 
    $(".product ." + sProduct).addClass("selected"); 
    sBrand = split_address[1]; 
    $(".brand ." + sBrand).addClass("selected"); 
    sCategory = split_address[2]; 
    sPage = split_address[3]; 
    sSearch = split_address[4]; 
    loadQuery(); 
} 



$('#left_menu ul li a').click(function(e){ 
    e.preventDefault(); 
}); 
$('#pagination_box a').live("click", function(e){ 
    e.preventDefault(); 
}); 
$('#pagination_box #prev').live("click", function(){ 
    $(this).live("click",function(){ 
     return false; 
    }); 
    sPage--; 
    window.location.hash = sProduct + ":" + sBrand + ":" +      sCategory +":"  +   sPage + ":" + sSearch;  
    loadQuery(); 
}); 
$('#pagination_box #next').live("click", function(){ 
    $(this).live("click",function(){ 
     return false; 
    }); 
    sPage++; 
    window.location.hash = sProduct + ":" + sBrand + ":" + sCategory +          ":"     +  sPage + ":"    +         sSearch; 
               loadQuery(); 
}); 
$('#pagination_box #page').live("click", function(){ 
    $(this).live("click",function(){ 
     return false; 
    }); 

    newsPage = $(this).stripHtml(); 
    sPage = newsPage.html() 
    window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" + 
           loadQuery(); 
}); 
function loadQuery() { 

     $('#content').html("<br /><br /><br /><center><img src=\"/images  /loading.gif\" alt=\"loading\"/><br /><p>Please wait...</p></center>"); 
     $.get("/serv_category.php", { product: sProduct, brand: sBrand,  category:       sCategory, page: sPage, search: sSearch }, 
      function(data,status){ 

       $('#content').html(data); 
     }); 
} 
$('#searchinput').live("keyup", function(e) { 
    if(e.keyCode == 13) { 
    sSearch = $('#searchinput').val(); 
    window.location.hash = sProduct + ":" + sBrand + ":" + sCategory +       ":"  +     sPage + ":" + sSearch; 
    loadQuery(); 
    } 
}); 
$('#left_menu ul li').click(function(){ 
    $(this).click(function(){ 
     return false; 
    }); 
    if ($(this).attr('class') != "title") { 

     if ($(this).parent().attr('class') == "product") { 
      if ($(this).attr('class') != "all") { 

       oldsProduct = sProduct; 
       $(".product ." +                  oldsProduct).removeClass("selected");     sProduct = $(this).attr('class'); 
       $(this).addClass("selected"); 
      } else { 
       oldsProduct = sProduct; 
       $(".product ." + oldsProduct).removeClass("selected"); 
       sProduct = $(this).attr('class'); 
       sProduct = "any"; 
      } 
     } 
     if ($(this).parent().attr('class') == "brand") { 
      if ($(this).attr('class') != "all") { 
       oldsBrand = sBrand; 
       $(".brand ." + oldsBrand).removeClass("selected"); 
       sBrand = $(this).attr('class'); 
       $(this).addClass("selected"); 
      } else { 
       oldsBrand = sBrand; 
       $(".brand ." + oldsBrand).removeClass("selected"); 
       sBrand = $(this).attr('class'); 
       sBrand = "any"; 
      } 
     } 
     if ($(this).parent().attr('class') == "category") { 
      if ($(this).attr('class') != "all") { 
       sCategory = $(this).attr('class'); 
       $(this).addClass("selected"); 
      } else { 
       sCategory = "any"; 
      } 
     } 
     sPage=1; 
     window.location.hash = sProduct + ":" + sBrand + ":" + sCategory + ":" +          sPage             +       ":" + sSearch; 
                 loadQuery(); 


       }; 
        }); 
        }); 
+0

不要叫出聲來,你需要幫助。這沒有意義。只需以聰明的方式提出問題。我已經刪除了標題和問題中的噪音。 – BalusC

回答