All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
如何获取客户端已安装的所有字体?_[Asp.Net教程]
动态网页技术PHP通过参数来生成MYSQL语句类_php资料_编程技术
解决SQL Server 2000中讨厌的Bug_[SQL Server教程]
关于生成验证码的源码以及问题解决_.net资料_编程技术
ASP.NET效率陷阱之——Attributes_[Asp.Net教程]
SQL2000中默认sa帐号改名和删除的最安全方法_[SQL Server教程]
构建安全的Xml,Web,Service系列
全面接触SQL语法(6)_[SQL,Server教程]
asp.net2.0对Repeater数据控件进行绑定
DropDownList绑定数据库字段获取下拉列表值_[Asp.Net教程]
Reading number is top 10 pictures
Average female college students3
原子弹轰炸长崎的珍贵照片
30 beautiful school beauty1
Fender Bender that so horrifying1
China telecom 114 spokesman MeiYanXu1
影评-疯子,我爱你
徐若瑄展示美丽胸围3
Magnificent cloud2
Chinese paper-cut grilles art appreciation2
NeedWallpaper11
Download software ranking
Tram sex maniac 2 (H) rar bag9
Ashlynn Video4
金山office2007
功夫熊猫2(上集)
jdk1.6 for windows
Tram sex maniac 2 (H) rar bag2
The Bermuda triangle1
SQL2000 For 4IN1
Call Of Duty5
Dance with duck(male prostitution)
归海一刀 published in(发表于) 2014/1/30 1:10:50 Edit(编辑)
新瓶旧酒ASP.NET,AJAX(2),-,客户端脚本编程(命名空间、类、成员、接口、继承、枚举)_[Asp.Net教程]

新瓶旧酒ASP.NET,AJAX(2),-,客户端脚本编程(命名空间、类、成员、接口、继承、枚举)_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(2) - 客户端脚本编程(命名空间、类、成员、接口、继承、枚举)_[Asp.Net教程]

新瓶旧酒ASP.NET AJAX(2) - 客户端脚本编程(命名空间、类、成员、接口、继承、枚举)



介绍
Microsoft AJAX Library提供了对JavaScript的扩展和对面向对象的支持,并且与.NET框架非常相似。我们来看一下如何实现命名空间、类、成员、接口、继承和枚举。



关键
1、Sys.Type类
·Type.registerNamespace("命名空间的名称");
·classInstanceVar.registerClass("类名称", 基类(可选), 接口(可选,多个就顺序写下去));
·typeInstanceVar.registerInterface("接口名称");
·ANamespace.AnEnum.registerEnum("枚举名称");
·typeVar.initializeBase(初始化基类的实例(一般是this), [传值给基类构造函数的参数](可选) ); (返回值为基类的实例)
·instanceVar.callBaseMethod(调用基类方法的实例(一般是this), "基类的方法名称", [传值给基类方法的参数](可选));
·其它请查看官方文档


2、为了使“partial-page rendering”有效,应该像如下这样引用外部js





3、为了使ScriptManager正确的处理脚本,在每一个js文件的结尾处都应该包括如下这句
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


示例
Sample.js
// 注册一个名为“Demo”的命名控件
Type.registerNamespace("Demo");


// 定义Demo命名空间下的Message类的构造函数
Demo.Message = function(content, publishTime)
{
this._content = content;
this._publishTime = publishTime;
}


// 定义Demo命名空间下的Message类的方法
Demo.Message.prototype =
{

get_content: function()
{
return this._content;
},

get_publishTime: function()
{
return this._publishTime.format("yyyy-MM-dd HH:mm:ss");
},

toString: function()
{
return this.get_content() + " " + this.get_publishTime();
}


}


// 在Demo命名空间下注册Message类
Demo.Message.registerClass('Demo.Message');



// 定义在Demo命名空间下的IContent接口(接口不能有构造函数)
Demo.IContent = function()
{


}


// 定义Demo命名空间下的IContent接口的方法
Demo.IContent.prototype =
{
showContent : function()
{

}
}


// 在Demo命名空间下注册IContent接口
Demo.IContent.registerInterface('Demo.IContent');


// 定义Demo命名空间下的MessageWithUserId类的构造函数
// 我们之后要让这个类继承自Demo.Message
// 在构造函数内用initializeBase调用基类的构造函数
Demo.MessageWithUserId = function(userId, content, publishTime)
{
Demo.MessageWithUserId.initializeBase(this, [content, publishTime]);

this._userId = userId;
}


// 定义Demo命名空间下的MessageWithUserId类的方法
Demo.MessageWithUserId.prototype =
{
get_userId: function()
{
return this._userId;
},

showContent: function()
{
return Demo.MessageWithUserId.callBaseMethod(this, 'get_content')
},

// callBaseMethod用于调用基类的方法
toString: function()
{
return this.get_userId() + " " + Demo.MessageWithUserId.callBaseMethod(this, 'toString');
}
}


// 在Demo命名空间下注册MessageWithUserId类
// 他继承自Demo.Message类和Demo.IContent接口
Demo.MessageWithUserId.registerClass('Demo.MessageWithUserId', Demo.Message, Demo.IContent);



// 定义在Demo命名空间下的Color枚举(枚举不能有构造函数)
Demo.Color = function()
{


}


// 定义Demo命名空间下的Color枚举的成员
Demo.Color.prototype =
{
// “0x”代表16进制,eval一下就会变成10进制的整型
Red: 0xFF0000,
Blue: 0x0000FF,
Green: 0x00FF00,
White: 0xFFFFFF
}


// 在Demo命名空间下注册Color枚举
Demo.Color.registerEnum("Demo.Color");



// 只有对异步回发才需要向脚本文件中的 Sys.Application.notifyScriptLoaded 方法添加调用
// 建议在每一个js文件的结尾处都应该包括如下这句
// 通知ScriptManager这段脚本已经加载完毕
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Sample.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sample.aspx.cs"
Inherits="ClientScripting_Sample" Title="命名空间,类,成员,接口,继承,枚举" %>









onclick="return btnTestClass_onlick()" />



onclick="return btnTestInheritance_onclick()" />



枚举的测试





运行结果
1、单击“类的测试”按钮后
hello 2007-05-28 08:47:11
hello 2007-05-28 08:47:11


2、单击“类、接口和继承的测试”按钮后
webabcd hello 2007-05-28 08:48:16
webabcd hello 2007-05-28 08:48:16
hello
true


3、选择“枚举的测试”的选项后
页面会变成你选择的颜色

作者:webabcd

[源码下载]







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.