thinkPHP实现的联动菜单功能
文章主要介绍了thinkPHP实现的联动菜单功能,结合实例形式分析了thinkPHP联动菜单的实现步骤与具体操作技巧,需要的'朋友可以参考下.
本文实例讲述了thinkPHP实现的联动菜单功能。分享给大家供大家参考,具体如下:
联动菜单,首先给你看看前端是怎么写的:
<p id="newCat">
<p class="all_type" id="allGoogsCat">所有商品分类</p>
<p class="spfl-warp <?php if(CONTROLLER_NAME != 'Index' || ACTION_NAME != 'index'){echo 'hide';} ?> ">
<p class="index-spfl-left" id="pCatList">
<ul>
<foreach name="category_menu" key="one" item="v">
<li class="li{$one+1}">
<span><em></em>
<a href="{:U('Category/index',array('id'=>$v['category_id'],'level'=>1))}" rel="external nofollow" >{$v.category_name}</a>
</span>
<p class="p none">
<foreach name="v['childs']" key="two" item="v2">
<dl>
<dt>
<a href="{:U('Category/index',array('id'=>$v2['category_id'],'level'=>2))}" rel="external nofollow" >{$v2.category_name}</a>
</dt>
<dd class="fl">
<foreach name="v2['childs']" item="v3">
<a href="{:U('Category/index',array('id'=>$v3['category_id'],'level'=>3))}" rel="external nofollow" >
{$v3.category_name}
</a>
</foreach>
</dd>
<p class="cl"></p>
</dl>
</foreach>
</p>
</li>
</foreach>
</ul>
</p>
</p>
</p>
<script type="text/javascript">
<?php if(CONTROLLER_NAME != 'Index' || ACTION_NAME != 'index'){ ?>
//商品分类鼠标滑过
function spflHover() {
$(".index-spfl-left ul li").live("mouseover", function () {
$(this).addClass("active").siblings().removeClass("active");
$(".index-spfl-left").find(".p").hide();
$(this).find(".p").show();
}).live("mouseout", function () {
$(this).removeClass("active");
$(".index-spfl-left").find(".p").hide();
$(this).find(".p").hide();
});
//鼠标滑过分类显示
$("#newCat").mouseover(function () {
$(".spfl-warp").show();
}).mouseout(function () {
if ($("#ismain").val() == "1") {
$(".spfl-warp").show();
} else {
$(".spfl-warp").hide();
}
})
}
spflHover();
<?php } ?>
</script>
看到没有,其实里面的一级菜单对应二级菜单都是在同一个li里面的,li里面的二级三级呢,都是放在dl的dt和dd标签里面;
然后现在我们看看取出来的category_menu,什么样的数据:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71