Home > Backend Development > PHP Tutorial > How to filter js code with multiple conditions in php

How to filter js code with multiple conditions in php

小云云
Release: 2023-03-20 20:46:01
Original
2098 people have browsed it

This article mainly shares with you how to filter js code with multiple conditions in PHP. This article mainly shares it with you in the form of code. I hope it can help you master the method of filtering js code with multiple conditions in PHP.

<dl class="dl-lst clear">
<dt>房型:</dt>
<dd class="dd show-more">
<p class="option-list" data-type="fangxing">
<a href="javascript:void(0);" data-xftrack="10134"  rel="nofollow" class="on">不限</a>
<a href="javascript:goSort(&#39;goods_htypeid&#39;,1);" data-xftrack="10134"  rel="nofollow" >1室</a>
<a href="javascript:goSort(&#39;goods_htypeid&#39;,2);" data-xftrack="10134"  rel="nofollow" >2室</a>
<a href="javascript:goSort(&#39;goods_htypeid&#39;,3);" data-xftrack="10134"  rel="nofollow" >3室</a>
<a href="javascript:goSort(&#39;goods_htypeid&#39;,4);" data-xftrack="10134"  rel="nofollow" >4室</a>
</p>
</dd>
</dl>
<dl class="dl-lst clear">
<dt>售价:</dt>
<dd class="dd show-more">
<p class="option-list" >
<a href="javascript:void(0);" data-xftrack="10134" class="on" rel="nofollow">不限</a>
<a href="javascript:goSort(&#39;price&#39;,1);" data-xftrack="10134"  rel="nofollow">100万以下</a>
<a href="javascript:goSort(&#39;price&#39;,2);" data-xftrack="10134"  rel="nofollow">100-150万</a>
<a href="javascript:goSort(&#39;price&#39;,3);" data-xftrack="10134"  rel="nofollow">150-200万</a>
<a href="javascript:goSort(&#39;price&#39;,4);" data-xftrack="10134"  rel="nofollow">200-250万</a>
<a href="javascript:goSort(&#39;price&#39;,5);" data-xftrack="10134"  rel="nofollow">250-300万</a>
<a href="javascript:goSort(&#39;price&#39;,6);" data-xftrack="10134"  rel="nofollow">300万以上</a>
<p class="custom" data-type="price">
<!-- <p class="txt-box">
<input type="text" class="txt" name="min_price" data-index="2" value="" />
</p> - 
<p class="txt-box">
<input type="text" class="txt" name="max_price" data-index="2" value="" />
</p>
 万
<input type="button" data-type="price" class="ok" value="确定" /> -->
</p>
</p>
</dd>
</dl>
<dl class="dl-lst clear">
<dt>特色:</dt>
<dd class="dd show-more">
<p class="option-list" >
<a href="javascript:void(0);" data-xftrack="10134" class="on" rel="nofollow">不限</a>
<a href="javascript:goSort(&#39;tese&#39;,1);" data-xftrack="10134"  rel="nofollow">观景飘窗</a>
<a href="javascript:goSort(&#39;tese&#39;,2);" data-xftrack="10134"  rel="nofollow">低密度</a>
<a href="javascript:goSort(&#39;tese&#39;,3);" data-xftrack="10134"  rel="nofollow">花园洋房</a>
<a href="javascript:goSort(&#39;tese&#39;,4);" data-xftrack="10134"  rel="nofollow">车位充足</a>
</p>
</dd>
</dl>
<dl class="dl-lst clear">
<dt>类型:</dt>
<dd class="dd show-more">
<p class="option-list" >
<a href="javascript:void(0);" data-xftrack="10134" class="on" rel="nofollow">不限</a>
<a href="javascript:goSort(&#39;goods_wy_type&#39;,1);" data-xftrack="10134"  rel="nofollow">住宅</a>
<a href="javascript:goSort(&#39;goods_wy_type&#39;,2);" data-xftrack="10134"  rel="nofollow">别墅</a>
<a href="javascript:goSort(&#39;goods_wy_type&#39;,3);" data-xftrack="10134"  rel="nofollow">写字楼</a>
<a href="javascript:goSort(&#39;goods_wy_type&#39;,4);" data-xftrack="10134"  rel="nofollow">商铺</a>
<a href="javascript:goSort(&#39;goods_wy_type&#39;,5);" data-xftrack="10134"  rel="nofollow">底商</a>
</p>
</dd>
</dl>
<dl class="dl-lst clear">
<dt>售卖:</dt>
<dd class="dd show-more">
<p class="option-list" >
<a href="javascript:void(0);" data-xftrack="10134" class="on" rel="nofollow">不限</a>
<a href="javascript:goSort(&#39;ifshou&#39;,1);" data-xftrack="10134"  rel="nofollow">在售</a>
<a href="javascript:goSort(&#39;ifshou&#39;,2);" data-xftrack="10134"  rel="nofollow">售罄</a>
</p>
</dd>
</dl>
</p>
</p>
</p>
</p>
<script type="text/javascript">
    function getQueryString(){
     var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g"));
     if(result == null){
         return "";
     }
     for(var i = 0; i < result.length; i++){
         result[i] = result[i].substring(1);
     }
     return result;
}
function goSort(name,value){
    var string_array = getQueryString();
    var oldUrl = (document.URL.indexOf("loupan.html")==-1)?document.URL+"loupan.html":document.URL;
    var newUrl;
    // alert(name)
    // alert(value)
    
    if(string_array.length>0)//如果已经有筛选条件
    {   
        var repeatField = false;
        for(var i=0;i<string_array.length;i++){
            if(!(string_array[i].indexOf(name)==-1)){
                repeatField = true;//如果有重复筛选条件,替换条件值
                newUrl = oldUrl.replace(string_array[i],name+"="+value);
            }
        }
        // 如果没有重复的筛选字段
        if(repeatField == false){
            newUrl = oldUrl+"&"+name+"="+value;
        }
    }
    if(string_array.length==false)
    {
        newUrl = document.URL+"?"+name+"="+value;
    }
    // alert(newUrl)
    //跳转
    window.location = newUrl;
}
function setSelected(name,value){
    var all_li = $("#"+name).find("li");
    //清除所有li标签的selected类
    all_li.each(function(){
        $(this).removeClass("selected");
    });
    //为选中的li增加selected类
    all_li.eq(value).addClass("selected");
}
$(document).ready(function(){
    var string_array = getQueryString();
    for(var i=0;i<string_array.length;i++){
        var tempArr = string_array[i].split("=");
        setSelected(tempArr[0],tempArr[1]);//设置选中的筛选条件
    }
});
</script>
Copy after login

Related recommendations:

javascript - How to do multi-condition filtering query in php

The above is the detailed content of How to filter js code with multiple conditions in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template