本帖最后由 lyh5719 于 2010-07-01 10:42:18 编辑

解决方案 »

  1.   


    $s = '<SELECT id=deptId name=deptId> <OPTION class=gray value="" 
            selected>===不限===</OPTION><OPTION class=blue value=2019>└合作销售</OPTION> 
            <OPTION class=blue value=49>&nbsp;&nbsp;├江南证券</OPTION> <OPTION 
            class=blue value=50>&nbsp;&nbsp;│&nbsp;&nbsp;├深圳营业部</OPTION> <OPTION 
            class=blue value=51>&nbsp;&nbsp;│&nbsp;&nbsp;├上海营业部</OPTION> <OPTION 
            class=blue value=57>&nbsp;&nbsp;│&nbsp;&nbsp;├杭州营业部</OPTION> <OPTION 
            class=blue value=2000>&nbsp;&nbsp;│&nbsp;&nbsp;├重庆营业部</OPTION> <OPTION 
            class=blue value=2003>&nbsp;&nbsp;│&nbsp;&nbsp;├昆明营业部</OPTION> <OPTION 
            class=blue value=2004>&nbsp;&nbsp;│&nbsp;&nbsp;├北京营业部</OPTION> <OPTION 
            class=blue value=2005>&nbsp;&nbsp;│&nbsp;&nbsp;├天津营业部</OPTION> <OPTION 
            class=blue value=2006>&nbsp;&nbsp;│&nbsp;&nbsp;├武汉营业部</OPTION> <OPTION 
            class=blue value=2007>&nbsp;&nbsp;│&nbsp;&nbsp;├郑州中原路营业部</OPTION> 
            <OPTION class=blue 
            value=2029>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└投资理财部</OPTION> <OPTION 
            class=blue value=2008>&nbsp;&nbsp;│&nbsp;&nbsp;├南昌营业部</OPTION> <OPTION 
            class=blue 
            value=2021>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;├南昌营业部营销中心</OPTION> 
            <OPTION class=blue 
            value=2022>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;├南昌营业部客服中心</OPTION> 
            <OPTION class=blue 
            value=2023>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└南昌营业部运营中心</OPTION> 
            <OPTION class=blue value=2009>&nbsp;&nbsp;│&nbsp;&nbsp;├吉安营业部</OPTION> 
            <OPTION class=blue value=2010>&nbsp;&nbsp;│&nbsp;&nbsp;├景德镇营业部</OPTION> 
            <OPTION class=blue value=2011>&nbsp;&nbsp;│&nbsp;&nbsp;├上饶营业部</OPTION> 
            <OPTION class=blue 
            value=2020>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└客服中心</OPTION> <OPTION 
            class=blue value=2012>&nbsp;&nbsp;│&nbsp;&nbsp;├宜春营业部</OPTION> <OPTION 
            class=blue value=2013>&nbsp;&nbsp;│&nbsp;&nbsp;├丰城营业部</OPTION> <OPTION 
            class=blue value=2014>&nbsp;&nbsp;│&nbsp;&nbsp;├赣州营业部</OPTION> <OPTION 
            class=blue 
            value=2028>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└客服中心</OPTION> <OPTION 
            class=blue value=2015>&nbsp;&nbsp;│&nbsp;&nbsp;├郑州嵩山路营业部</OPTION> 
            <OPTION class=blue value=2016>&nbsp;&nbsp;│&nbsp;&nbsp;├泉州营业部</OPTION> 
            <OPTION class=blue 
            value=2030>&nbsp;&nbsp;│&nbsp;&nbsp;│&nbsp;&nbsp;└客服部</OPTION> <OPTION 
            class=blue value=2017>&nbsp;&nbsp;│&nbsp;&nbsp;├总部</OPTION> <OPTION 
            class=blue value=2031>&nbsp;&nbsp;│&nbsp;&nbsp;├九江营业部</OPTION> <OPTION 
            class=blue value=2032>&nbsp;&nbsp;│&nbsp;&nbsp;├萍乡营业部</OPTION> <OPTION 
            class=blue value=2033>&nbsp;&nbsp;│&nbsp;&nbsp;└乐平营业部</OPTION> <OPTION 
            class=blue value=2024>&nbsp;&nbsp;└测试营业部</OPTION></SELECT>';
    echo $s;
      

  2.   

    js就可以了。var select_value = "";
    function TreeView(obj,target){
    this.obj=obj;
    this.root=new node(-1,-1,"");
    this.nodes=[];
    this.currentNode=null;
    this.html="";
    this.config={ blank :'|-',
    line :'|-'
    };
    for(i in this.config){var tem=this.config[i];this.config[i]=new Image();this.config[i].txt=tem;}
    };function node(id,pid,txt){
    this.id=id;
    this.pid=pid;
    this.txt=txt;
    this.indent="";
    this.open=false;
    this.lastNode=false;
    this.hasNode=false;
    };
    TreeView.prototype.add=function(id,pid,txt){
    var itemTxt=txt?txt:"New Item";
    this.nodes[this.nodes.length]=new node(id,pid,itemTxt);
    };TreeView.prototype.DrawTree=function(pNode){
    var str="";
    for(var i=0;i<this.nodes.length;i++){
    if(this.nodes[i].pid==pNode.id){
    str+=this.DrawNode(this.nodes[i].id,i);
    }
    }
    return str;
    };TreeView.prototype.ChkPro=function(pNode){
    var last;
    for(var n=0;n<this.nodes.length;n++){
    if(this.nodes[n].pid==pNode.id){
    pNode.hasNode=true;
    }
    if (this.nodes[n].pid == pNode.pid){last= this.nodes[n].id;}
    }
    if (last==pNode.id){pNode.lastNode = true;}
    };TreeView.prototype.DrawNode=function(id,nid){
    var str="";
    var select_ed = "";
    var nNode=this.nodes[nid];
    this.DrawLine(nNode,nNode);
    if(nNode.hasNode)
    {nNode.indent+=(nNode.hasNode?"":"");}
    if (select_value==id){select_ed = "selected"}else{select_ed = "";}
    str+="<option value="+id+" "+select_ed+">"+nNode.indent+this.DrawLink(nid)+"</option>";
    if(nNode.hasNode){
    str+=this.DrawTree(nNode);
    }
    return str;
    };
    TreeView.prototype.DrawLine=function(nNode,tem){
    for(var i=0;i<this.nodes.length;i++){
    if(this.nodes[i].id==tem.pid){
    nNode.indent=(this.nodes[i].lastNode?this.config.blank.txt:this.config.line.txt)+nNode.indent;
    this.DrawLine(nNode,this.nodes[i]);
    }
    }
    };
    TreeView.prototype.DrawLink=function(nid){
    var nNode=this.nodes[nid];
    return nNode.txt;
    };TreeView.prototype.toString=function(){
    var str="";
    this.ChkPro(this.root);
    for(var i=0;i<this.nodes.length;i++)this.ChkPro(this.nodes[i]);
    str+=this.DrawTree(this.root);
    return str;
    };<script language="javascript" src="js/select_tree.js"></script>
    <SCRIPT LANGUAGE="JavaScript">
    var m=new TreeView('m','main')
    var select_value = "<?php echo $select_value;?>";
    m.add(0,-1,'ROOT');
    <?php
    foreach($newclassdb as $class){
        echo "m.add({$class['id']},{$class['pid']},'{$class['text']}');";
    }
    ?>
    document.write("<div class=box1><div class=box2><select name='cid'>"+m+"</select></div></div>");
    </SCRIPT>
      

  3.   

    树型下拉框,你应该格式化下你的数据,问明白点。
    你可以按以下的数组格式构建一个完整点的数据,再发出来,懒得帮你构建数据了。
    $tree = array('id'=>'1','pid'=>0,'text'=>'所有部门',value=>'2000')
      

  4.   

    sorry,这样才对
    $tree[] = array('id'=>'1','pid'=>0,'text'=>'所有部门',value=>'2000')