当前位置: 首页 > 图文教程 > 网络编程 > Javascript > TreeView(扩充XMLSelTree)(二)

Javascript
JavaScript 继承详解(四)
兼容IE/Firefox/Opera/Safari的检测页面装载完毕的脚本Ext.onReady的实现
js 实现无缝滚动 兼容IE和FF
js 对象是否存在判断
优化 JavaScript 代码的方法小结
表单元素事件 (Form Element Events)
js 动态创建 html元素
prototype 学习笔记整理
JavaScript 创建对象
javascript 全角转换实现代码
DOM 基本方法
用showModalDialog弹出页面后,提交表单总是弹出一个新窗口
javascript 动态创建 Option选项
javascript 7行代码画出一个围棋棋盘
比较简单的异步加载JS文件的代码
javascript 层隐藏和显示的代码
自定义滚动条3.0
javascript iframe内的函数调用实现方法
Prototype Class对象学习
Prototype RegExp对象 学习

Javascript 中的 TreeView(扩充XMLSelTree)(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 363 ::
收藏到网摘: n/a

TreeView(扩充XMLSelTree

VisualSW

基于XMLJavaScriptTreeView

}

            else

            {

                ReadNode(Element.childNodes[i],s_Text,s_Value,OP);

            }

        }            

    }

    else

    {

        //alert(Element.getAttribute("Title") + Element.getAttribute("CheckData") + Element.getAttribute("Checked"));

        if((Element.getAttribute("Title")==s_Text) && (Element.getAttribute("CheckData")==s_Value))

        {               

            switch(OP)

            {

                case "ADD":

                    var NewNode = oXMLDom.createNode(1, "TreeNode", "");

                    NewNode.setAttribute("Title",ipt_Title.value);

                    NewNode.setAttribute("CheckData","000");

                    NewNode.setAttribute("CHK","true");

                    Element.appendChild(NewNode);

                    break;

                case "MODIFY":

                    Element.setAttribute("Title",ipt_Title.value);

                    Element.setAttribute("Caption",ipt_Caption.value);

                    break;

                case "DELETE":

                    Element.parentNode.removeChild(Element);

                    break;

                default:

                    break;

            }           

        }

    }

}

 

/*

======================================================================

JavaScript鼠标右键菜单

作者:申旺

日期:2004/05/13

注意:

======================================================================

*/

 

var Style;

Style="<style>" +

".skin0" +

"{" +

"      position:absolute;" +

"      text-align:left;" +

"      width:80px;" +

"   border-top-style: #000000 2px solid;" +

"   border-right-style: #000000 2px solid;" +

"   border-left-style: #000000 2px solid;" +

"   border-bottom-style: #000000 2px solid;" +

"      background-color:menu;" +

"      font-family:Verdana;" +

"      line-height:20px;" +

"      cursor:default;" +

"      visibility:hidden;" +

"}" +

".skin1" +

"{" +

"      cursor:default;" +

"      font:menutext;" +

"      position:absolute;" +

"      text-align:left;" +

"      font-family: Arial, Helvetica, sans-serif;" +

"      font-size: 10pt;" +

"      width:120px;" +

"      background-color:menu;" +

"      border:1 solid buttonface;" +

"      visibility:hidden;" +

"      border:2 outset buttonhighlight;" +

"}" +

".menuitems" +

"{" +

"   font-size: 9pt;" +

"   font-family: \"宋体\",Arial;" +

"      padding-left:15px;" +

"      padding-right:10px;" +

"}" +

"-->" +

"</style>";

 

var OutDiv;

OutDiv="<div id=\"ie5menu\" class=\"skin1\" onMouseover=\"highlightie5()\" onMouseout=\"lowlightie5()\">" +

"<div class=\"menuitems\" onclick=\"domenu('close')\">返回</div>" +

"<hr>"+

"<div class=\"menuitems\" onclick=\"domenu('modify')\">修改</div>"+

"<hr>"+

"<div class=\"menuitems\" onclick=\"domenu('add')\">增加</div>"+

"<hr>"+

"<div class=\"menuitems\" onclick=\"domenu('delete')\">删除</div>"+

"</div>";

 

var AddORModify;

AddORModify="<div id=\"addormodify\" class=\"skin0\">" +

"Title:<input id=ipt_Title type=textbox value=\"\">" + "<br>" +

"Caption:<input id=ipt_Caption type=textbox value=\"\">" + "<br>" +

"<input id=btn_Cancel type=button value='取消' onclick=\"JavaScript:HideAddOrModify();\">" +

"<input id=btn_Submit type=button value='确定' onclick=\"JavaScript:Submit();\">" +

"<input type=hidden id=hid_Text value=''><input type=hidden id=hid_Value value=''>" +

"</div>";

 

var Select_Text;

var Select_Value;

 

function Init()

{  

    //write AddOrModify

       document.write(AddORModify);

      

       //write style   

       document.write(Style);

      

       //write menu   

       document.write(OutDiv);

      

       if(document.all&& window.print)

       {

              //ie5menu.className= menuskin;

              document.oncontextmenu= DoNothing;

              document.body.onclick= HideMenuIE5;

       }

}

 

function DoNothing()

{

    return false;

}

 

//初始化右键菜单

Init();

 

function ShowMenuIE5(p_Text,p_Value)

{   

    Select_Text=p_Text;

    Select_Value=p_Value;

   

       var rightedge= document.body.clientWidth-event.clientX;

       var bottomedge= document.body.clientHeight-event.clientY;

       if(rightedge< ie5menu.offsetWidth)

       ie5menu.style.left= document.body.scrollLeft+ event.clientX -

       ie5menu.offsetWidth;

       else

       ie5menu.style.left= document.body.scrollLeft+ event.clientX;

       if(bottomedge< ie5menu.offsetHeight)

       ie5menu.style.top= document.body.scrollTop+ event.clientY -

       ie5menu.offsetHeight;

       else

       ie5menu.style.top= document.body.scrollTop+ event.clientY;

       ie5menu.style.visibility="visible";

      

       addormodify.style.visibility="hidden";

      

       return false;

}

 

function HideMenuIE5()

{

    Select_Text="";

    Select_Value="";

       ie5menu.style.visibility="hidden";

       //addormodify.style.visibility="hidden"; 

}

 

function highlightie5()

{

       if(event.srcElement.className=="menuitems")

       {

              event.srcElement.style.backgroundColor="highlight";

              event.srcElement.style.color="white";         

       }

}

 

function lowlightie5()

{

       if(event.srcElement.className=="menuitems")

       {

              event.srcElement.style.backgroundColor="";

              event.srcElement.style.color="black";

              window.status="";

       }    

}

 

function domenu(src)

{   

    switch(src)

    {

        case "return":

            HideMenuIE5();

            break;

        case "delete":

            if(confirm("确认删除?"))

            {

                DeleteNode(Select_Text,Select_Value);

            }

            break;

        case "add":          

            ShowAddOrModify("add");

            break;

        case "modify":           

            ShowAddOrModify("modify");

        default:

            break;       

    }

}

 

function Submit()

{   

    if(btn_Submit.value=="修改")

    {       

        ModifyNode(hid_Text.value,hid_Value.value);

        HideAddOrModify();

    }

    else

    {

        AddNode(hid_Text.value,hid_Value.value);

        HideAddOrModify();

    }

}

 

function HideAddOrModify()

{

    Select_Text=="";

    Select_Value=="";

    addormodify.style.visibility="hidden";

    ipt_Title.value="";

    ipt_Caption.value="";

}

 

function ShowAddOrModify(src)

{

   

    var rightedge= document.body.clientWidth-event.clientX;

       var bottomedge= document.body.clientHeight-event.clientY;

       if(rightedge< addormodify.offsetWidth)

       addormodify.style.left= document.body.scrollLeft+ event.clientX -

       addormodify.offsetWidth;

       else

       addormodify.style.left= document.body.scrollLeft+ event.clientX;

       if(bottomedge< addormodify.offsetHeight)

       addormodify.style.top= document.body.scrollTop+ event.clientY -

       addormodify.offsetHeight;

       else

       addormodify.style.top= document.body.scrollTop+ event.clientY;

       addormodify.style.visibility="visible";   

      

    if(src=="modify")

    {       

        ipt_Title.value=Select_Text;

        ipt_Caption.value=Select_Text;

        hid_Text.value=Select_Text;

        hid_Value.value=Select_Value;

        btn_Submit.value="修改";

    }

    else

    {

        ipt_Title.value="";

        ipt_Caption.value="";

        hid_Text.value=Select_Text;

        hid_Value.value=Select_Value;

        btn_Submit.value="新增";

    }   

}

代码不是很规范,给大家参考。