TreeView(扩充XMLSelTree)
基于XML、JavaScript的TreeView。
}
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="新增";
}
}
代码不是很规范,给大家参考。