首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

关于Dtree的简略应用

2012-11-04 
关于Dtree的简单应用第一:下载dtree的样式和脚本文件包,放入自己的程序包第二:dtree的数据添加格式就不再

关于Dtree的简单应用
第一:下载dtree的样式和脚本文件包,放入自己的程序包
第二:dtree的数据添加格式就不再多说
第三:如果需要进行调用自己的脚本文件,则在添加进树结构的菜单中无需指定target 名称,当然至于dtree.js文件你则可以自己修改,一般修改的地方都是
if (node.url) {
str += '<a id="s' + this.obj + nodeId + '" href="' + node.url + '"';

if (node.title) str += ' title="' + node.title + '"';

if (node.target) str += ' target="' + node.target + '"';

if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';

if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))

str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';

//is my update
str+= ' oncontextmenu="javascript:showMenu('+node.id+')"'
//str += '';

str += '>';
}
当然,做右键菜单也是在这里修改代码的,网上很多说dtree加右键菜单,可是却没有提到修改dtree.js文件。
第四:简单右键菜单--只有删除功能
html页面
添加右键的<Div>:

 
<div id="itemMenu" style="display:none">   
  <table border="1" width="100%" bgcolor="#D0D0D0" style="border:thin" cellspacing="0">   
 
    <tr>   
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.delNode()">删除</td>   
    </tr>   
 
  </table>   
</div>     
一个用于存放值的form表单:
<form name = "menuForm">   
     <!--隐藏框,用来保存选择的菜单的id值-->   
     <input type = "hidden" name = "id" value = ""/>
               <div == id)   
    {   
        popMenu(itemMenu,100,"1000");   
    }   
    else   
    {   
        popMenu(itemMenu,100,"1111");   
    }   
        event.returnValue=false;   
        event.cancelBubble=true;   
        return false;   
}  
/**  
*显示弹出菜单  
*menuDiv:右键菜单的内容  
*width:行显示的宽度  
*rowControlString:行控制字符串,0表示不显示,1表示显示,如“101”,则表示第1、3行显示,第2行不显示  
*/   
function popMenu(menuDiv,width,rowControlString)   
{   
    //创建弹出菜单   
    var pop=window.createPopup();   
    //设置弹出菜单的内容   
    pop.document.body.innerHTML=menuDiv.innerHTML;   
    var rowObjs=pop.document.body.all[0].rows;   
    //获得弹出菜单的行数   
    var rowCount=rowObjs.length;   
    //循环设置每行的属性
    for(var i=0;i<rowObjs.length;i++)   
    {   
        //如果设置该行不显示,则行数减一   
        var hide=rowControlString.charAt(i)!='1';   
        if(hide){   
            rowCount--;   
        }   
        //设置是否显示该行   
        rowObjs[i].style.display=(hide)?"none":"";   
        //设置鼠标滑入该行时的效果   
        rowObjs[i].cells[0].onmouseover=function()   
        {   
            this.style.background="#aec3de";   
            this.style.color="red";   
        }   
        //设置鼠标滑出该行时的效果   
        rowObjs[i].cells[0].onmouseout=function(){   
            this.style.background="#5cb4dd";   
            this.style.color="#000000";   
        }   
    }   
       
    //屏蔽菜单的菜单   
    pop.document.oncontextmenu=function()   
    {   
            return false;   
    }   
    //选择右键菜单的一项后,菜单隐藏   
    pop.document.onclick=function()   
    {   
            pop.hide();   
    }   
    //显示菜单   
    pop.show(event.clientX-1,event.clientY,width,rowCount*25,document.body);   
    return true;   
}   
function delNode()   
{   
//alert(menuForm.id.value)
   window.location.href="organizeEnter?handle=MagorClassCtrl_delDone&morgId="+menuForm.id.value;
}   


</script>
还有就是修改dtree.js文件部门,如上修改

热点排行