织梦的栏目管理非常帅,多级栏目显示上面非常清晰,今天大象仿了个织梦的多级栏目管理,废话不多说,上代码
1、递归类 Typeunit.calss.php
<?
class Typeunit {
/**
* 读出所有分类,在类目管理页(list_type)中使用
*
* @access public
* @param int $table 表名
* @param int $topid 当前操作ID
* @return string
*/
public function ListType($table='keshi',$topid=0){
$Form = M($table);
$list = $Form->where('topid='.$topid)->order("sort desc,id asc")->select();
foreach ($list as $k => $v) {
echo '<tr align="center" bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
$this->ListTypeSeed($table,$v['id']);
}
}
/**
* 读出子分类
*
* @access public
* @param int $table 表名
* @param int $topid 当前操作ID
* @return string
*/
private function ListTypeSeed($table,$topid){
$Form = M($table);
$list = $Form->where('topid='.$topid)->order("sort desc,id asc")->select();
if($list){
echo '<tr align="center" bgcolor="#FFFFFF" height="22" class="seed"><td colspan="4"><table width="98%">';
foreach ($list as $k => $v) {
echo '<tr align="center" bgcolor="#FAFAF1" height="22"><td width="7%"><span class="jia"></span>ID</td><td width="14%">'.$v['id'].'</td><td width="14%">'.$v['name'].'</td><td>操作</td></tr>';
$this->ListTypeSeed("keshi",$v['id']);
}
echo '</table></td></tr>';
}
}
}
?>2、模板页面 index.html<script>
$(function(){
/*
* 点击展开子类
*
*/
$(".jia").click(function(){
if($(this).parent("td").parent("tr").next(".seed").is(":hidden")){
$(this).parent("td").parent("tr").next(".seed").show();
$(this).html("-");
}else{
$(this).parent("td").parent("tr").next(".seed").hide();
$(this).html("+");
}
});
//初始化全部都是-号
$(".seed").prev(".fid").find("td").find("span.jia").html("-");
/*
* 点击关闭所有子类
*
*/
$("#closeseed").click(function(){
if($(this).val() == "展开所有子类"){
$(".seed").show();
$(this).val("关闭所有子类");
$.each($(".jia"),function(k,v){
if($(this).html()){
$(this).html("-");
}
});
}else{
$(".seed").hide();
$(this).val("展开所有子类");
$.each($(".jia"),function(k,v){
if($(this).html()){
$(this).html("+");
}
});
}
});
});
</script>
<php>
$tu = new Typeunit();
$tu->ListType('keshi',0);
</php> 