欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用MS AJAX注冊(cè)Javascript命名空間并創(chuàng)建類

 更新時(shí)間:2007年10月27日 12:06:03   作者:  
一、為頁(yè)面添加一個(gè)ScriptManager控件。

二、注冊(cè)命名空間:

Type.registerNamespace("Demo");


三、為類添加構(gòu)造函數(shù)、屬性、方法。

Demo.sample=function(){}

四、注冊(cè)類。

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


下面是一個(gè)具體的實(shí)例:

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代碼:

<!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>


<body>

<form id="Main" runat="server">

<asp:ScriptManager runat="server" ID="scriptManager" />

</form>


<div>

<p>This example creates an instance of the Person class 

and puts it in the "Demo" namespace.</p>


<input id="Button1" value="Create Demo.Person" 

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


</div>


<script type="text/javascript" src="Namespace.js"></script>

<script type="text/javascript" language="JavaScript">


function OnButton1Click() 

{

var testPerson = new Demo.Person( 

'John', 'Smith', 'john.smith@example.com');

alert(testPerson.getFirstName() + " " + 

testPerson.getLastName() );


return false;

}



</script>


</body>

</html>


保存后看下運(yùn)行效果。

相關(guān)文章

最新評(píng)論