利用MS AJAX注册Javascript命名空间并创建类
|
一、为页面添加一个ScriptManager控件。 二、注册命名空间: Type.registerNamespace("Demo");
Demo.sample=function(){} 四、注册类。 Demo.Person.registerClass("Demo.sample ", null, Sys.IDisposable);
http://edu.cnzz.cn/NewsInfo/Namespace.js Type.registerNamespace("Demo");
this._firstName = firstName; this._lastName = lastName; this._emailAddress = emailAddress; }
return this._firstName; },
return this._lastName; },
return this._firstName + " " + this._lastName; },
alert("bye " + this.getName()); } } Demo.Person.registerClass("Demo.Person", null, Sys.IDisposable);
Namespace.aspx代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Namespace</title> </head>
<form id="Main" runat="server"> <asp:ScriptManager runat="server" ID="scriptManager" /> </form>
<p>This example creates an instance of the Person class and puts it in the "Demo" namespace.</p>
type="button" onclick="return OnButton1Click()" />
<script type="text/javascript" language="JavaScript">
{ var testPerson = new Demo.Person( "John", "Smith", "john.smith@example.com"); alert(testPerson.getFirstName() + " " + testPerson.getLastName() );
}
</script>
</html>
|
