通过拼接url 传参数搜索
<foreach name="cat_per" item="vo">
<a href="javascript:;" id="per" b="pre" class="get-type" data="{$vo.aa_name}">{$vo.aa_name}</a>
</foreach>
/
//点击省份去掉城市
$(".get-types1").click(function () {
var val = $(this).attr('data');
var type = $(this).attr('d');
var url_param = window.location.search.replace('?', '');//获取链接
var url_base = window.location.href.replace(url_param, '');
var set_url = '';
if (url_param.length == 0) {
set_url = url_base + '?' + type + '=' + val;
// alert(set_url);
} else {
if (url_param.indexOf(type) == '-1') {
set_url = url_base + url_param + '&' + type + '=' + val;
} else {
var arr = url_param.split('&');
$.each(arr, function (index, value) {
if (value.indexOf(type) >= 0) {
arr[index] = type + '=' + val;
}
});
//删除要删除的url里面的参数
for (var i in arr) {
if (arr[i].indexOf('area') >= 0) {
// arr.index($(this))
console.log(i);
arr.splice(i, 1);
}
}
// console.log(arr);
var param = arr.join('&');
set_url = url_base + param;
}
}
window.location.href = set_url;
});
//样式css
var url_param = decodeURI(window.location.search.replace('?', ''));
if (url_param.length > 0) {
var arr = url_param.split('&');
var getType = $(".get-types1");
// console.log(getType);
$.each(arr, function (index, value) {
var arr_tow = value.split('=');
$.each(getType, function (i, v) {
if (arr_tow[0] == v.getAttribute('d') && arr_tow[1] == v.getAttribute('data')) {
$.each($(".active"), function (ii, vv) {
if (v.getAttribute('d') == vv.getAttribute('d')) {
$(this).removeClass('active');
}
});
$(this).addClass('active');
}
})
});
}