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

DTree完全施用+右键菜单

2012-10-27 
DTree完全使用+右键菜单dtree 动态树+Javascript右键菜单(一)注:先看效果,不行了你就不用看,免得浪费大家

DTree完全使用+右键菜单
dtree 动态树+Javascript右键菜单(一)
注:先看效果,不行了你就不用看,免得浪费大家的时间。行了你再看。


1、从网上下载dtree控件。下面是dtree的下载地址http://destroydrop.com/javascripts/tree/
2、解压缩dtree.rar包。
    把dtree目录下的dtree.js 拷贝至scripts文件中、
    dtree.css  拷贝至styles文件中、
    img文件和example01.html拷贝至工程根目录下。
    注意:除了api.html之外,其它的文件都是必须拷贝的。只有这个api.html是对dtree控件的函数介绍。
3、将 example01.html文件重命名为Tree.jsp

4、在Web应用中指定首页为Tree.jsp页面。
5、 Tree.jsp中的代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Destroydrop &raquo; Javascripts &raquo; Tree</title>
<link rel="StyleSheet" href="styles/dtree.css" type="text/css" />
<script type="text/javascript" src="scripts/dtree.js"></script>
</head>
<body>
<div 打印树节点:"+sb.toString());
/************************************************************************/

return mapping.findForward("projectShow");
}
4、修改 Tree.jsp页面
修改其中生成树的javascript代码:
    <div name = "id" value = "">
    <table><tr><td>
    <div 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.addNode()">新增</td>
    </tr>

    <tr>
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.delNode()">删除</td>
    </tr>

    <tr>
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.updateNode()">更新</td>
    </tr>
  </table>
</div>
<!-- 右键结束 -->

到这里就定义了右键菜单中有三项:新增、删除、更新

4、定义页面的右键弹出事件的javascript函数
<script language="JavaScript">
/**
*根据传入的id显示右键菜单
*/
function showMenu(id)
{
    menuForm.id.value = id;
    if("" == 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 create()
{
    alert("create" + menuForm.id.value + "!");
}
function update()
{
    alert("update" + menuForm.id.value + "!");
}
function del()
{
    alert("delete" + menuForm.id.value + "!");
}
function select()
{
    alert("select" + menuForm.id.value + "!");
}
function clickMenu()
{
    alert("you click a menu!");
}
</script>

热点排行