栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

利用MS AJAX注册Javascript命名空间并创建类

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用MS AJAX注册Javascript命名空间并创建类

一、为页面添加一个scriptManager控件。

二、注册命名空间:

Type.registerNamespace("Demo");


三、为类添加构造函数、属性、方法。

Demo.sample=function(){}

四、注册类。

Demo.Person.registerClass('Demo.sample ', null, Sys.IDisposable);


下面是一个具体的实例:

Namespace.js

Type.registerNamespace("Demo");


Demo.Person = function(firstName, lastName, emailAddress) {

this._firstName = firstName;

this._lastName = lastName;

this._emailAddress = emailAddress;

}


Demo.Person.prototype = {


getFirstName: function() {

return this._firstName;

},


getLastName: function() {

return this._lastName;

},


getName: function() {

return this._firstName + ' ' + this._lastName;

},


dispose: function() {

alert('bye ' + this.getName());

}

}

Demo.Person.registerClass('Demo.Person', null, Sys.IDisposable); Namespace.aspx代码:


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





Namespace











This example creates an instance of the Person class 

and puts it in the "Demo" namespace.





type="button" onclick="return OnButton1Click()" />















保存后看下运行效果。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/59683.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号