php如何多條件篩選js程式碼

小云云
發布: 2023-03-20 20:46:01
原創
2048 人瀏覽過

本文主要跟大家分享php如何多條件篩選js程式碼,本文主要是以程式碼的形式來跟大家分享,希望能幫助大家掌握php多條件篩選js程式碼的方法。

<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>
登入後複製

相關建議:

javascript - php多條件篩選查詢怎麼做

#

以上是php如何多條件篩選js程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!