当前位置: 代码迷 >> Java Web开发 >> jq多条件筛选解决方法
  详细解决方案

jq多条件筛选解决方法

热度:35   发布时间:2016-04-14 21:19:39.0
jq多条件筛选
本帖最后由 ahao303 于 2015-03-23 12:52:22 编辑
http://demo.198zone.com/linktolink/ 
这个是demo地址

以下是下载地址
http://www.198zone.com/othercode/2014091247.html

默认是筛选是
http://demo.198zone.com/linktolink/?ddd=2&aaa=1 在当前的html 筛选
我想跳转到一个固定的 URL“ /search.php?p?modelid=2&query=&”
接着筛选


换一个问法吧,

我有一个静态的html 

www.yuming.com/cases01/list.html  套上这个代码后会出现如下
www.yuming.com/cases01/list.html?bbb=1&aaa=2&ccc=2

我需求是
必须跳到www.yuming.com//search.php?modelid=2&query=&bbb=1&aaa=2&ccc=2

红色部分为跳转的固定URL





以下是js部分代码

$.fn.sx = function(can) {
    can = $.extend({
        nuv: ".zj",//筛选结果
zi: "sx_child",//所有筛选范围内的子类
qingchu:'.qcqb',//清除全部
over:'on'//选中状态样式名称
    },
    can || {});
/*删选过程*/
    $(this).find('a').click(function() {
        var url = window.location.href;
        var id = $(this).attr('rel');
        var id2 = $(this).attr('name');
        var index = $(this).index();
        var num = $(this).parent().find('a').length;
        var num2 = $(this).parents(can).length;
if($(this).attr('class').replace(can.zi,'').replace(/ /g,'')=="on"){

var url = window.location.href;
        var pddq = $(this).attr('name') + "=" + $(this).attr('rel');
        if (url.split('&').length < 2) {
             url = url.replace('?' + pddq, '')
        } else {
             if (url.split(pddq)[0].split('&').length < 2) {
                 url = url.replace(pddq + '&', '')
              } else {
                   url = url.replace('&' + pddq, '')
                }
            }

}else{
 if (url.split('?').length < 2) {
            url = url + "?" + id2 + "=" + id
        } else {
            if (url.split('&').length < 2) {
                if (url.split('?')[1].split('=')[0] == id2) {
                    url = url.replace(url.split('?')[1], id2 + "=" + id)
                } else {
                    url = url + "&" + id2 + "=" + id
                }
            } else {
                if (url.split(id2).length > 1) {
                    if (url.split(id2)[0].split('&').length < 2) {
                        url = url.replace(url.split(id2)[1].split('&')[0], "=" + id)
                    } else {
                        if (url.split(id2)[1].split('&').length < 2) {
                            url = url.replace(id2 + url.split(id2)[1], id2 + "=" + id)
                        } else {
                            url = url.replace(id2 + url.split(id2)[1].split('&')[0], id2 + "=" + id)
                        }
                    }
                } else {
                    url = url + "&" + id2 + "=" + id
                }
            }
        }
}
        window.location.href = url
    })

window.onload = function() {
/*选中*/
        $("."+can.zi).each(function() {
            var url = window.location.href;
            var pddq = $(this).attr('name') + "=" + $(this).attr('rel');
            if (url.split(pddq).length > 1) {
                $(this).addClass('on');
                $(can.nuv).find(can.qingchu).before("<a rel=" + $(this).attr('rel') + " name=" + $(this).attr('name') + " href='javascript:;'>" + $(this).siblings('span').text() + $(this).text() + "</a> ")
            } else {
                $(this).removeClass('on')
            }
        })
/*清除全部按钮是否显示*/
var url = window.location.href;
if(url.split('?').length>1){
$(can.qingchu).show();
}else{
$(can.qingchu).hide();
}
/*点击清除*/
$(can.nuv).find('a').click(function() {
     var url = window.location.href;
        var pddq = $(this).attr('name') + "=" + $(this).attr('rel');
        if (url.split('&').length < 2) {
             url = url.replace('?' + pddq, '')
        } else {
             if (url.split(pddq)[0].split('&').length < 2) {
                 url = url.replace(pddq + '&', '')
              } else {
                   url = url.replace('&' + pddq, '')
                }
            }
            window.location.href = url;
        })
/*清除全部*/
$(can.qingchu).click(function(){
var url = window.location.href;
url = url.split('?')[0];
window.location.href = url;
})
    }
}

------解决思路----------------------
引用:
www.yuming.com//search.php?modelid=2&query=&bbb=1&aaa=2&ccc=2
1. 怎么俩斜杠?
2. 先截取域名,然后后边拼接不行么?


------解决思路----------------------
处理字符串不就好了啊
  相关解决方案