仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 897|回复: 18
打印 上一主题 下一主题

[学习教程] PHP网页编程之一个很适用亲睦用的资本办理器的树形目...

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
#
发表于 2015-2-4 00:09:40 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在学习PHP这六个月里,每看到一个优秀的php脚本,就会兴奋的手舞足蹈,嘴里还不停的说:太酷了,太酷了。呵呵,很幼稚吧,但这可能就是兴趣。   来源根基码从网高低载,经自己改写,功效更壮大,利用更便利,可以有没有限级目次,一次性载入,可以分离设置树结点和叶结点的色彩及图标,可以睁开和压缩,可以显示以后所处的途径地位,点击树结点时只在睁开时显示树结点的超链接,不外,据测试,一次性载入500个节点时阅读器会显示“该剧本会使阅读器变慢”的提醒,不外,选择不作废履行不会影响阅读器的功能。
function folder(folderdescription, hreference,parentid,target) {
//constant data;

this.desc = folderdescription;
this.parentid=parentid;
this.hreference = hreference;
this.target=target;
this.id = index;
this.navobj = 0;
this.iconimg = 0;
this.nodeimg = 0;
this.islastnode = 0;

// dynamic data
this.isroot = true;
this.isopen = true;
this.iconsrc=imageurl+"ftv2folderopen.gif";
this.iconroot =imageurl+"ftv2folderopen.gif";

this.children = new array;
this.nchildren = 0;

// methods
this.initialize = initializefolder;
this.setstate = setstatefolder;
this.addchild = addchild;

this.createindex = createentryindex;
this.hide = hidefolder;
this.display = display;
this.renderob = drawfolder;
this.totalheight = totalheight;
this.subentries = foldersubentries;
this.outputlink = outputfolderlink;

}

function setstatefolder(isopen) {
var subentries;
var totalheight;
var fit = 0;
var i = 0;
if(isopen == this.isopen)
return;
if(browserversion == 2) {
totalheight = 0
for(i = 0; i < this.nchildren; i++)
totalheight = totalheight + this.children.navobj.clip.height;
subentries = this.subentries();
if(this.isopen)
totalheight = 0 - totalheight;
for(fit = this.id + subentries + 1; fit < nentries; fit++)
indexofentries[fit].navobj.moveby(0, totalheight);
}
this.isopen = isopen;
propagatechangesinstate(this);
}

function propagatechangesinstate(folder) {
var i = 0;
if(folder.isopen) {
if(folder.nodeimg) {
if(folder.islastnode)
folder.nodeimg.src = imageurl+"ftv2mlastnode.gif";
else
folder.nodeimg.src = imageurl+"ftv2mnode.gif";
}
if(this.isroot)
folder.iconimg.src = imageurl+"ftv2_mail.gif";
else
folder.iconimg.src = imageurl+"ftv2folderopen.gif";
for(i = 0; i < folder.nchildren; i++)
folder.children.display();
}
else {
if(folder.nodeimg) {
if(folder.islastnode)
folder.nodeimg.src = imageurl+"ftv2plastnode.gif";
else
folder.nodeimg.src = imageurl+"ftv2pnode.gif";
}
if(this.isroot)
folder.iconimg.src = imageurl+"ftv2_mail.gif";
else
folder.iconimg.src = imageurl+"ftv2folderclosed.gif";
for(i = 0; i < folder.nchildren; i++)
folder.children.hide();
}
}
function hidefolder() {
if(browserversion == 1) {
if(this.navobj.style.display == "none")
return;
this.navobj.style.display = "none";
}
else {
if(this.navobj.visibility == "hiden")
return;
this.navobj.visibility = "hiden";
}
this.setstate(0);
}

function initializefolder(level, lastnode, leftside) {
var i = 0;
var j = 0;
var numberoffolders;
var numberofdocs;
nc = this.nchildren;
this.createindex();
var nc;
var auxev = "";
if(browserversion > 0)
auxev = "<a href='javascript: clickonnode("+this.id+")'>";
else
auxev = "<a>";
if(level > 0) {
if(lastnode) { //the last 'brother' in the children array
this.renderob(leftside + auxev + "<img name='nodeicon" + this.id + "' src='"+imageurl+"ftv2mlastnode.gif' width=16 height=22 border=0></a>");
leftside = leftside + "<img src=\'"+imageurl+"ftv2blank.gif\' width=16 height=22>";
this.islastnode = 1;
}
else {
this.renderob(leftside + auxev + "<img name='nodeicon" + this.id + "'src=\'"+imageurl+"ftv2mnode.gif\' width=16 height=22 border=0></a>");
leftside = leftside + "<img src=\'"+imageurl+"ftv2vertline.gif\' width=16 height=22>";
this.islastnode = 0;
}
}
else {
this.renderob("");
}
if(nc > 0) {
level = level + 1;
for(i = 0; i < this.nchildren; i++) {
if(i == this.nchildren-1)
this.children.initialize(level, 1, leftside);
else
this.children.initialize(level, 0, leftside);
}
}
}

function drawfolder(leftside) {
if(browserversion == 2) {
if(!doc.ypos)
doc.ypos = 8;
doc.write("<layer id='folder" + this.id + "' top=" + doc.ypos + " visibility=hiden>");
}
doc.write("<table")
if(browserversion == 1)
doc.write(" id='folder" + this.id + "' style='position:block;' ");
doc.write(" border=0 cellspacing=0 cellpadding=0>");
doc.write("<tr><td>");
doc.write(leftside);
this.outputlink();
doc.write("<img name='foldericon" + this.id + "' ");
if(leftside == '') {
doc.write("src='" + this.iconroot+"' border=0></a>");
}
else {
doc.write("src='" + this.iconsrc+"' border=0></a>");
}
doc.write("</td><td nowrap>");
doc.write("<div class=\"fldrroot\">");
if(leftside == '') {
if(usetextlinks) {
this.outputlink();
doc.write('<font size="2" color="'+flodercolor+'">'+this.desc + "</font></a>");
}
else
doc.write(this.desc);
}
else {
doc.write("<a href='javascript: clickonnode("+this.id+")'>");
doc.write('<font size="2" color="'+flodercolor+'">'+this.desc + "</font></a>");
}
doc.write("</div>");
doc.write("</td>");
doc.write("</table>");
if(browserversion == 2) {
doc.write("</layer>");
}
if(browserversion == 1) {
this.navobj = doc.all["folder"+this.id];
this.iconimg = doc.all["foldericon"+this.id]
this.nodeimg = doc.all["nodeicon"+this.id]
}
else if(browserversion == 2) {
this.navobj = doc.layers["folder"+this.id];
this.iconimg = this.navobj.document.images["foldericon"+this.id];
this.nodeimg = this.navobj.document.images["nodeicon"+this.id];
doc.ypos = doc.ypos + this.navobj.clip.height;
}
}
<body bgcolor=#c0c693 leftmargin=5 topmargin=5 marginwidth="5" marginheight="5">
<script language=javascript src="../leftfiles/treemenu.js"></script>
<script language=javascript>
//以下三项可以设置也能够按默许值,main和parent.main都是链接页面要显示的方针框架
setimageurl("images/"); //图标途径
setlinkcolor("#ff0000");//叶节点链接色彩
setflodercolor("#ffff00");//树结点链接色彩

folderstree = gfldr('***引见','','');
aux1 = insfldr(folderstree, "**机关",parent.main,"function.htm");
aux2 = insfldr(aux1 , "**处",parent.main,"function.htm");
insdoc(aux2 , "main", "**室","department/manage/offic.htm");
insdoc(aux2 , "main", "**室", "department/manage/employee.htm");
insdoc(aux2 , "main", "**室","department/manage/finance.htm");
aux2 = insfldr(aux1 , "**处",parent.main,"function.htm");
insdoc(aux2 , "main", "**室","department/manage/law.htm");
insdoc(aux2 , "main", "**室","department/manage/manage.htm");
insdoc(aux2 , "main", "**室", "department/manage/custody.htm");
insdoc(aux2 , "main", "**室", "department/manage/marketmanage.htm");
aux3 = insfldr(aux2 , "**处",parent.main,"function.htm");
insdoc(aux3 , "main", "**室", "department/manage/policy.htm");
insdoc(aux3 , "main", "**室", "department/manage/disposition.htm");
aux1 = insfldr( folderstree,"**中间",parent.main,"department/business/function.htm");
aux2 = insfldr(aux1 , "**处",parent.main,"function.htm");
insdoc(aux2 , "main", "**室","department/manage/offic.htm");
insdoc(aux2 , "main", "**室", "department/manage/employee.htm");
insdoc(aux2 , "main", "**室","department/manage/finance.htm");
aux2 = insfldr(aux1 , "**处",parent.main,"function.htm");
insdoc(aux2 , "main", "**室","department/manage/law.htm");
insdoc(aux2 , "main", "**室","department/manage/manage.htm");
insdoc(aux2 , "main", "**室", "department/manage/custody.htm");
insdoc(aux2 , "main", "**室", "department/manage/marketmanage.htm");
aux3 = insfldr(aux2 , "**处",parent.main,"function.htm");
insdoc(aux3 , "main", "**室", "department/manage/policy.htm");
insdoc(aux3 , "main", "**室", "department/manage/disposition.htm");

initializedocument();
</script>
function outputfolderlink() {
if(this.hreference && this.target) {
doc.write("<a href='" + this.hreference + "' target=\""+this.target.name+"\" ")
if(browserversion > 0) {
doc.write("")
}
doc.write(">")
}
else
doc.write("<a>")
}

function addchild(childnode) {
selectfile[fentries]=childnode.desc;
fentries++;
this.children[this.nchildren] = childnode;
this.nchildren++;
return(childnode);
}

function foldersubentries() {
var i = 0;
var se = this.nchildren;
for(i = 0; i < this.nchildren; i++) {
if(this.children.children) //is a folder
se = se + this.children.subentries();
}
return(se)
}

// definition of class item (a document or link inside a folder)
function item(itemdescription, hreference, itemlink, itemimg,parentid) // constructor
{
// constant data
this.desc = itemdescription
this.link = itemlink
this.hreference = hreference;
this.id =index;
this.navobj = 0; //initialized in render()
this.iconimg = 0; //initialized in render()
// iconsrc俊 瘤沥登绰 捞固瘤 颇老阑 阿 酒捞袍俊 嘎霸 瘤沥且 荐 乐档废 茄促 (格钎)
this.iconsrc = itemimg;
// methods
this.initialize = initializeitem ;
this.createindex = createentryindex;
this.hide = hideitem;
this.display = display;
this.renderob = drawitem;
this.totalheight = totalheight;
this.parentid=parentid;
//alert(this.parent);
}

function hideitem() {
if(browserversion == 1) {
if(this.navobj.style.display == "none")
return;
this.navobj.style.display = "none"
}
else {
if(this.navobj.visibility == "hiden")
return;
this.navobj.visibility = "hiden";
}
}

function initializeitem(level, lastnode, leftside) {
this.createindex();
if(level > 0) {
if(lastnode) { //the last 'brother' in the children array
this.renderob(leftside + "<img src='"+imageurl+"ftv2lastnode.gif' width=16 height=22>")
leftside = leftside + "<img src='"+imageurl+"ftv2blank.gif' width=16 height=22>"
}
else {
this.renderob(leftside + "<img src='"+imageurl+"ftv2node.gif' width=16 height=22>")
leftside = leftside + "<img src='"+imageurl+"ftv2vertline.gif' width=16 height=22>"
}
}
else
this.renderob("")
}

function drawitem(leftside) {
if(browserversion == 2)
doc.write("<layer id='item" + this.id + "' top=" + doc.ypos + " visibility=hiden>");
doc.write("<table ");
if(browserversion == 1)
doc.write(" id='item" + this.id + "' style='position:block;' ");
doc.write(" border=0 cellspacing=0 cellpadding=0>");
doc.write("<tr><td>");
doc.write(leftside);
if(this.link != "") doc.write("<a onclik=\'veiwfile("+this.id+")\' href=" + this.link + ">");
doc.write("<img id='itemicon"+this.id+"' ")
doc.write("src='"+this.iconsrc+"' border=0>")
if(this.link != "")
doc.write("</a>");
doc.write("</td><td nowrap>");
doc.write("<div class=\"fldritem\">");
if(usetextlinks) {
if(this.link != "")
doc.write("<a onclick=\'veiwfile("+this.id+")\' href=" + this.link + '><font size="2" color="'+linkcolor+'">'+ this.desc + "</font></a>");
else
doc.write(this.desc);
}
else {
doc.write(this.desc);
}
doc.write("</div>");
doc.write("</table>")
if(browserversion == 2)
doc.write("</layer>");
if(browserversion == 1) {
this.navobj = doc.all["item"+this.id]
this.iconimg = doc.all["itemicon"+this.id]
}
else if(browserversion == 2) {
this.navobj = doc.layers["item"+this.id];
this.iconimg = this.navobj.document.images["itemicon"+this.id];
doc.ypos = doc.ypos+this.navobj.clip.height;
}
}
function addposition(id,str1){
if(id>0){
clickedfolder = indexofentries[id];
parentid=clickedfolder.parentid;
parentname=indexofentries[parentid];
pa=parentname.desc;
if(parentid==0)str=pa+str1;
else str='</font><font size=\"2\" color=\"#8f8f8f\">―></font><font size=\"2\" color="#aa0000">'+pa+str1;
addposition(parentid,str);
}
}
var str="";
function veiwfile (msg) {
var typelogo=typeof top.logo;
if(typelogo=="undefined")return;
var tpyeframe=typeof top.logo.top1;
if(tpyeframe=="undefined")return;
objdocument= top.logo.top1;
var foldertext="";
if(msg==0)foldertext=selectfile[msg];
else {
str='</font><font size=\"2\" color=\"#8f8f8f\">―></font></font><font size=\"2\" color="#aa0000">'+selectfile[msg];
addposition(msg,str);
foldertext=str;
}
objdocument.document.open();
objdocument.document.write('<font size=\"2\" color=\"#8f8f8f\"> 以后地位: </font> <font size=\"2\" color="#aa0000"> '+foldertext+"</font>");
objdocument.document.close();
}
// methods common to both objects (pseudo-inheritance)
function display() {
if(browserversion == 1)
this.navobj.style.display = "block";
else
this.navobj.visibility = "show";
}

function createentryindex() {
indexofentries[nentries] = this;
nentries++;
}

// total height of subentries open
function totalheight() { //used with browserversion == 2
var h = this.navobj.clip.height;
var i = 0;
if(this.isopen) { // is a folder and _is_ open
for(i = 0 ; i < this.nchildren; i++)
h = h + this.children.totalheight();
}
return h
}

// events
function clickonfolder(folderid) {
var clicked = indexofentries[folderid];
if(!clicked.isopen)
clickonnode(folderid);
if(clicked.isselected)
return;
}

function clickonnode(folderid) {
var clickedfolder = 0;
var state = 0;
clickedfolder = indexofentries[folderid];
state = clickedfolder.isopen;
if (!state){
if(clickedfolder.target)clickedfolder.target.location=clickedfolder.hreference; //点击folder时显示相干链接页面
veiwfile(folderid);
}
clickedfolder.setstate(!state); //open<->close
}

function initializedocument() {
if(doc.all)
browserversion = 1; //ie4
else if(doc.layers)
browserversion = 2; //ns4
else
browserversion = 0; //other
folderstree.initialize(0, 1, "");
//folderstree.display();
if(browserversion > 0) {
doc.write("<layer top="+indexofentries[nentries-1].navobj.top+"> </layer>");
// close the whole tree
clickonnode(0);
// open the root folder
clickonnode(0);
}
}

// auxiliary functions for folder-treee backward compatibility
function gfldr(description, hreference,parentid,target) {
var des;
index++;
if(fentries==0){
selectfile[fentries]=description;
fentries++;
}
des=description;
folder = new folder(des, hreference,parentid,target);
return(folder);
}

function glnk(target, description, linkdata, itemimg,parentid) {
fulllink = ""
if(target == 0 ||target=="") {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_blank\"";//显示在新开的窗体中
else
fulllink = "";
}
if(target == 1) {
if(linkdata != "" )
fulllink = "'"+linkdata+"' target=\"_slef\"";//显示在表单地点的框架或窗体中
else
fulllink = "";
}
else if(target == 2) {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_parent\""; //显示在包括表单的框架的父框架中
else
fulllink = "";
}
else if(target == 3) {
if(linkdata != "")
fulllink = "'"+linkdata+"' target=\"_top\"";//显示在顶层窗体中
else
fulllink = "";
}
else {//alert(target);
if(linkdata != "")
fulllink = "'"+linkdata+"' target="+target;//显示在target窗体中
else
fulllink = "";
}
index++; //以后节点编号
linkitem = new item(description, linkdata, fulllink, itemimg,parentid)
return linkitem
}

function insfldr(parentfolder, childfolder,target,hreference) {
var child;
var desc;
parentid=parentfolder.id;
child=gfldr(childfolder,hreference,parentid,target);
return(parentfolder.addchild(child));
}

function insdoc(parentfolder,target, description, linkdata, itemimg) {
var document;
var itemimg;
itemimg=imageurl+"bu.gif";
var desc;
parentid=parentfolder.id;
document=glnk(target, description, linkdata, itemimg,parentid);
parentfolder.addchild(document);
}
function setobjdocument(msg){
if (msg!=null){
objdocument=msg;
}
}
//设置睁开、压缩图片途径
function setimageurl(msg){
if (msg==null){
imageurl="../leftfiles/images/";
}else imageurl=msg;
}
//设置超链接文本色彩
function setlinkcolor(msg){
linkcolor=msg;
}
function setflodercolor(msg){
flodercolor=msg;
}
// global variables
usetextlinks = 1;
indexofentries = new array;
nentries = 0;
index=-1;  //节点编号
doc = document;
browserversion = 0;
selectedfolder = 0;
selectfile=new array;
fentries=0;
var objdocument,imageurl;
var linkcolor="#085dde";
var flodercolor="#292c08";
var type1=typeof top.logo;
if (type1=="undefined"){
objdocument=null;
}
if(imageurl==null){
setimageurl(imageurl);
}
将源代码和接前代码中的代码兼并成一个treemenu.js文件,在在页面中引入便可

培训的第一阶段,学习的是HTML/CSS/JavaScript基础。
蒙在股里 该用户已被删除
18#
 楼主| 发表于 2015-6-13 20:41:42 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
变相怪杰 该用户已被删除
17#
发表于 2015-6-10 10:52:43 | 只看该作者
当然这种网站的会员费就几十块钱。
再现理想 该用户已被删除
16#
发表于 2015-5-6 07:11:52 | 只看该作者
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
简单生活 该用户已被删除
15#
发表于 2015-5-1 10:09:25 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
老尸 该用户已被删除
14#
发表于 2015-4-30 01:44:29 | 只看该作者
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
深爱那片海 该用户已被删除
13#
发表于 2015-4-17 22:46:35 | 只看该作者
爱上php,他也会爱上你。
精灵巫婆 该用户已被删除
12#
发表于 2015-4-4 10:23:47 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
11#
发表于 2015-4-3 22:39:21 | 只看该作者
其实没啥难的,多练习,练习写程序,真正的实践比看100遍都有用。不过要熟悉引擎
山那边是海 该用户已被删除
10#
发表于 2015-3-20 12:18:37 | 只看该作者
学习php的目的往往是为了开发动态网站,phper就业的要求也涵盖了很多。我大致总结为:精通php和mysql
小女巫 该用户已被删除
9#
发表于 2015-3-17 17:08:26 | 只看该作者
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
莫相离 该用户已被删除
8#
发表于 2015-3-17 06:54:20 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
谁可相欹 该用户已被删除
7#
发表于 2015-3-12 16:37:50 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
金色的骷髅 该用户已被删除
6#
发表于 2015-3-11 21:10:47 | 只看该作者
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
小妖女 该用户已被删除
5#
发表于 2015-3-10 22:15:27 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
柔情似水 该用户已被删除
地板
发表于 2015-2-19 01:20:30 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
小魔女 该用户已被删除
板凳
发表于 2015-2-16 03:56:31 | 只看该作者
在学习的过程中不能怕麻烦,不能有懒惰的思想。学习php首先应该搭建一个lamp环境或者是wamp环境。这是学习php开发的根本。虽然网络上有很多集成的环境,安装很方便,使用起来也很稳定、
再见西城 该用户已被删除
沙发
发表于 2015-2-10 08:31:50 | 只看该作者
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
冷月葬花魂 该用户已被删除
楼主
发表于 2015-2-7 03:31:55 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-11-10 23:38

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表