小山

Ajax实现无刷新树

系统 1785 0
Ajax实现无刷新树
1.建立一个aspx页面
html代码
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head id ="Head1" runat ="server" >
< title > 小山 </ title >
< link type ="text/css" href ="../../Styles/tree_css/tree.css" rel ="stylesheet" >
</ head >
< body >
< form id ="Form1" runat ="server" >
< table width =100% cellpadding =0 cellspacing =0 border =0 >
< colgroup >
< col width =180 />
< col />
</ colgroup >
< tr >
< td >
< div class ="TreeMenu" id ="CategoryTree" style ="width:100%;height:489px" >
</ div >
</ td >
< td >
< iframe id =furl height =20 style ="height:497px;width:100%;" ></ iframe >
</ td >
</ tr >
</ table >

< script language ="jscript" >
function el(id)
{
return document.getElementById(id);
}

function ExpandSubCategory(iCategoryID)
{
var li_father = el( " li_ " + iCategoryID);
if (li_father.getElementsByTagName( " li " ).length > 0 ) // 分类已下载
{
ChangeStatus(iCategoryID);
return ;
}


li_father.className
= " Opened " ;

switchNote(iCategoryID,
true );
AjaxMethod.GetSubCategory(iCategoryID,GetSubCategory_callback);
}


function GetSubCategory_callback(response)
{
var dt = response.value.Tables[ 0 ];
if (dt.Rows.length > 0 )
{
var iCategoryID = dt.Rows[ 0 ].FatherID;
}

var li_father = el( " li_ " + iCategoryID);
var ul = document.createElement( " ul " );
for ( var i = 0 ;i < dt.Rows.length;i ++ )
{
if (dt.Rows[i].IsChild == 1 ) // 叶子节点
{
var li = document.createElement( " li " );
li.className
= " Child " ;
li.id
= " li_ " + dt.Rows[i].CategoryID;

var img = document.createElement( " img " );
img.id
= dt.Rows[i].CategoryID;
img.className
= " s " ;
img.src
= " ../../Styles/tree_css/s.gif " ;

var a = document.createElement( " a " );
var id = dt.Rows[i].CategoryID;
a.onmouseover
= function ()
{
PreviewImage(id);
}
;
a.href
= " javascript:OpenDocument(' " + dt.Rows[i].CategoryID + " '); " ;
a.innerHTML
= dt.Rows[i].CategoryName;
}

else
{
var li = document.createElement( " li " );
li.className
= " Closed " ;
li.id
= " li_ " + dt.Rows[i].CategoryID;

var img = document.createElement( " img " );
img.id
= dt.Rows[i].CategoryID;
img.className
= " s " ;
img.src
= " ../../Styles/tree_css/s.gif " ;
img.onclick
= function () {
ExpandSubCategory(
this .id);
}
;
img.alt
= " 展开/折叠 " ;

var a = document.createElement( " a " );
a.href
= " javascript:ExpandSubCategory( " +
dt.Rows[i].CategoryID
+ " ); " ;
a.innerHTML
= dt.Rows[i].CategoryName;
}

li.appendChild(img);
li.appendChild(a);
ul.appendChild(li);
}

li_father.appendChild(ul);

switchNote(iCategoryID,
false );
}


// 叶子节点的单击响应函数
function OpenDocument(iCategoryID)
{
// 预加载信息
PreloadFormUrl(iCategoryID);
}


function PreviewImage(iCategoryID)
{

}


function ChangeStatus(iCategoryID)
{
var li_father = el( " li_ " + iCategoryID);
if (li_father.className == " Closed " )
{
li_father.className
= " Opened " ;
}

else
{
li_father.className
= " Closed " ;
}

}


function switchNote(iCategoryID,show)
{
var li_father = el( " li_ " + iCategoryID);
if (show)
{
var ul = document.createElement( " ul " );
ul.id
= " ul_note_ " + iCategoryID;

var note = document.createElement( " li " );
note.className
= " Child " ;

var img = document.createElement( " img " );
img.className
= " s " ;
img.src
= " ../../Styles/tree_css/s.gif " ;

var a = document.createElement( " a " );
a.href
= " javascript:void(0); " ;
a.innerHTML
= " 请稍候 " ;

note.appendChild(img);
note.appendChild(a);
ul.appendChild(note);
li_father.appendChild(ul);
}

else
{
var ul = el( " ul_note_ " + iCategoryID);
if (ul)
{
li_father.removeChild(ul);
}

}

}


// 加载根节点
var tree = el( " CategoryTree " );
var root color: #000000; backgroun
分享到:
评论

Ajax实现无刷新树


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论