Window.location Javascript / JQuery / PHP问题

时间:2011-08-03 15:06:17

标签: php javascript jquery

我添加了几个新页面,其中包含左侧的菜单框,名为left_menu.php。但是,当点击2个新页面中的类别标题时,我不会被发送到正确的类别或任何类别。

我已经包含了J / Query 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目的地所需的结果,或者可以提出一个简单的替代方案吗?我已经包含了下面的脚本。

A

<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();


                 };
                     });
                    });

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用Jquery地址? 看看这个:http://www.asual.com/jquery/address