原文地址:http://hi.baidu.com/wizardchilde/item/abc8dc11a25414e65f53b1df
javascript 是使用js来控制html dom 的脚ben语言。
/*给树加载数据*/
function getTreeData(id,parentCode,procName,status,clickcallback)
{
if($("#"+id).find(">ul").html()=="" || $("#"+id).find(">ul").html()==null){
var thisdata=storage._get(parentCode);
if(thisdata=="" || thisdata==null || status== "0"){
PageMethods.GeTreeInfoForClient(procName,parentCode,treeResult);
}
else{
$("#"+id).find(">ul").append(thisdata+"");
treeInit();
}
}
function treeResult(result){
var appendCode="";
for(var i=0;i<result.length;i++){
appendCode=(result[i].ExistChind ? '<li id="'+result[i].Code+'"><span>'+result[i].Name+'</span><ul></ul></li>' : '<li id="'+result[i].Code+'"><span>'+result[i].Name+'</span></li>');
$("#"+id).find(">ul").append(appendCode);
}
storage._set(parentCode,$("#"+id).find(">ul").html());
treeInit();
}
function treeInit(){
$("#"+id).find(">ul").find("span").dblclick(function(){
if(clickcallback){//双击树上结点时的回调事件
clickcallback.apply(this,arguments);
}
}).hover(function(){$(this).addClass("spanhover");},function(){$(this).removeClass("spanhover");});
$("#"+id).treeview({//此节点构建其下的tree
collapsed: true,
toggle:function aa(){
getTreeData($(this).attr("id"),$(this).attr("id"),procName,null,clickcallback);
}}
);
}
}
pagemethods对象是由微软的<asp:ScriptManager enablepagemethod="true">而生成的页面js对象
此对象包含后台方法[后台类应加上"[System.Web.Script.Services.ScriptService]"特性;后台方法应标记为"[WebMethod]"]
C#:
[System.Web.Script.Services.ScriptService]
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string MyCSharp(string a)
{
return a;
}
}
html:
<body οnlοad="ExecCSharp()">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
</form>
</body>
js:
<script type="text/javascript">
function ExecCSharp() {
PageMethods.MyCSharp("a", sucss);
}
function sucss(data) {
alert(data);
}
</script>
aspx:
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
或者将其写到web.config中
js的面向对象,下次说.