歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 小技巧:自動完成樹狀列表的程序

小技巧:自動完成樹狀列表的程序

日期:2017/2/27 9:26:47   编辑:更多Linux
  這是我寫的自動完成樹狀列表的程序,其中的javascript來自PHPMyAdmin, 幫忙看看,如果你認為還可以,在你的網站發表吧,注明我的主頁地址就可以了,http://mrcool.5915.net 呵呵~~~    list_count=0; $this -> child_count=0; $this -> item_count=0; $this -> $imagesurl=$img_url; }    function makeScript()    { //列表所需的Java代碼 ?> parent_name[] = array("index"=>$this->list_count++, "name"=>$name); $this -> item_count=0; //子節點計數清零 return ($this -> list_count-1); //返回父節點索引 }    function AddChild($index,$name,$url,$target,$title)    { //參數說明: index -- 父節點索引 // name -- 子節點名稱(顯示)    // url -- 連接地址 // target -- 連接目標 // title -- 提示 //增加子節點 static $valid; if($valid!=$index)    { //子節點計數是否清零 $this->item_count=0; $valid=$index; }    //獲得子節點數組下標 $s1="item".$this->item_count++; $s="child".$index; $this -> child_name[$s][$s1] = array("name"=>$name, "url"=>$url, "target"=>$target, "title"=>$title); } function showTreeView(){ //顯示整個TreeView $this->makeScript(); //首先輸出JAVA代碼 for($i=0; $ilist_count; $i++)    { //依次顯示父節點 $id="el".$this->parent_name[$i]["index"]; $imgid="el".$this->parent_name[$i]["index"]."Img"; echo "  "; echo ""; echo "\n"; echo ""; echo ""; echo $this->parent_name[$i]["name"].""; echo "\n"; echo "  \n"; echo "  \n"; echo "\n"; echo "  \n"; }    //保證兼容性代碼 echo "\n"; }    }//end of class TreeView //下面是例子 $x=new TreeView;    //創建類 //父節點的返回值是索引值,可以放棄返回值.    $i=$x->AddParent("技術論壇"); //增加第一個父節點 $j=$x->AddParent("娛樂論壇");    //增加第二個父節點 //增加一個父節點下的子節點,可以不按照父節點的順序增加,    //但是同一個父節點下的子節點必須一次增加完畢,否則會產生錯誤的輸出    $x->AddChild($i,"PHP 技術論壇","","","");    $x->AddChild($i,"CGI 技術論壇","","","");    $x->AddChild($i,"ASP 技術論壇","","","");    $x->AddChild(0,"jsp 技術論壇","","","");    //如果知道父節點索引,也可以直接寫數值 //增加第二個父節點下的子節點    $x->AddChild($j,"重金屬音樂","1","2","3");    $x->AddChild($j,"流行音樂","4","5","6"); $x->showTreeView(); ?>




Copyright © Linux教程網 All Rights Reserved