日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

destoon任何页面实现自定义筛选的方法

發(fā)布時間:2023/11/21 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 destoon任何页面实现自定义筛选的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

任何頁面實現(xiàn)自定義篩選,不二開內(nèi)核文件,全部在模板中實現(xiàn),不影響升級,不使用搜索功能。

首頁在頁頭引入jquery.min.js 文件,默認的模板是有這個的。如果不是默認的模板,也沒這個文件,請去下載個。

然后在篩選的頁面引入以下JS代碼:

[php]
<script>
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].substrin(1);
}
return result;
}

function goSort(name,value){
var string_array = getQueryString();
var oldUrl = (document.URL.indexOf("index.php")==-1)?document.URL+"index.php":document.URL;
var newUrl;
if(string_array.length>0)//如果已經(jīng)有篩選條件
{ var repeatField = false;
for(var i=0;i<string_array.length;i++){
if(!(string_array[i].indexOf(name)==-1)){
repeatField = true;//如果有重復篩選條件,替換條件值
newUrl = oldUrl.replac(string_array[i],name+"="+value);
}
}

//如果沒有重復的篩選字段
if(repeatField == false){
newUrl = oldUrl+"&"+name+"="+value;
}

}else{//如果還沒有篩選條件
newUrl = oldUrl+"?"+name+"="+value;
}

//跳轉
window.location = newUrl;
}

function setSelected(name,value){
var all_li = $("#"+name).find("a");
//清除所有a標簽的now類
all_li.each(function(){
$(this).removeClass("now");
});
//為選中的a增加now類
all_li.eq(value).addClass("now");
}

$(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>
[/php]

然后在模板中引入條件語句,這下面的是篩選條件,看不懂的先學學,參考修改。

[php]
{php $condition = "status=3";}
{php $dmode = array('',1=&gt;" and price=0",2=&gt;" and price&gt;0");}
{php $dcatid = array('',1=&gt;" and catid=10",2=&gt;" and catid=11");}
{php $dprice = array('',1=&gt;" and price&lt;1001",2=&gt;" and price&gt;1000 and price&lt;2000",3=&gt;" and price&gt;2001 and price&lt;3000",4=&gt;" and price&gt;3001 and price&lt;5000",5=&gt;" and and price&gt;5001 and price&lt;10001",6=&gt;" and price&gt;10000");}
{php $order = isset($order) ? intval($order) : 0;}
{php $mode = isset($mode) ? intval($mode) : 0;}
{php $dorder = array('addtime desc','price desc','hits desc');}
{php $condition.= $dmode[$mode];}
{php $condition.= $dcatid[$catid];}
{php $condition.= $dprice[$price];}
{php $condition.=" order by $dorder[$order]";}
[/php]

篩選模板,僅供參考

[php]
<div class="left j-left wfs fz12">
<h3 class="template">收費模式<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs" id="mode">
<a class="now" href="javascript:goSort('mode',0);">全部</a>
<a href="javascript:goSort('mode',1);">商業(yè)模板</a>
<a href="javascript:goSort('mode',2);">免費模板</a>
</div>
<h3 class="template">模板類型<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs" id="catid">
<a class="now" href="javascript:goSort('catid',0);">全部</a>
<a href="javascript:goSort('catid',1);">平臺型</a>
<a href="javascript:goSort('catid',2);">小眾型</a>
</div>
<h3 class="template">價格<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs price" id="price">
<li> <a class="now" href="javascript:goSort('price',0);">全部</a></li>
<li> <a href="javascript:goSort('price',1);">1000以下</a></li>
<li><a href="javascript:goSort('price',2);">1000-2000</a></li>
<li> <a href="javascript:goSort('price',3);">2000-3000</a></li>
<li> <a href="javascript:goSort('price',4);">3000-5000</a></li>
<li> <a href="javascript:goSort('price',5);">5000-10000</a></li>
<li> <a href="javascript:goSort('price',6);">10000以上</a></li>
</div>

</div>

</div>

<div class="right j-right" style="margin-left: 300px;">
<div class="sort wfs">
<div style="float:left;">
<span style="margin-left:45px; float:left; padding-top:5px; font-size:12px;">排序:</span>

<span class="sort-icons j-sort-icons" id="order">
<a class="now" rel="nofollow" href="javascript:goSort('order',0);">新品</a>
<a rel="nofollow" href="javascript:goSort('order',1);">價格</a>
<a rel="nofollow" href="javascript:goSort('order',2);">熱銷</a>
</span>

</div>

</div>
[/php]

循環(huán)語句中&condition=后面加入上$condition
大功 告成。

轉自:http://www.dtmoban.com/Course/5/3.html

總結

以上是生活随笔為你收集整理的destoon任何页面实现自定义筛选的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。