?? 20-1 向?qū)嵗刑砑幼远x屬性和方法.htm
字號(hào):
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>20-1 向?qū)嵗刑砑幼远x屬性和方法</title>
<style>
* { font-size:12px; font-family:宋體, Arial; } /*規(guī)定了所有的字體樣式*/
</style>
<script>
function User(name){
this.name;
this.init = function(name){
if(!name){
this.name = "默認(rèn)名稱";
}else{
this.name = name;
}
this.print("我已初始化結(jié)束");
}
this.login = function(password){
this.print("我在執(zhí)行登錄操作");
}
this.print = function(str){
document.write("["+this.name+"]:"+str+"<br>");
}
this.init(name);
}
//創(chuàng)建新的“User”類實(shí)例
user1 = new User("hutia");
user1.newName = "hutia2";
user1.remove = function(){ this.print("我被移除了!"); }
//創(chuàng)建新的“User”類實(shí)例
user2 = new User("axiang");
//調(diào)用“User類”實(shí)例的方法
user1.print("我的新屬性\"newName\"的值是\""+user1.newName+"\"");
user2.print("我的新屬性\"newName\"的值是\""+user2.newName+"\"");
user1.print("我的新方法\"remove\"的內(nèi)容是\""+user1.remove+"\"");
user2.print("我的新方法\"remove\"的內(nèi)容是\""+user2.remove+"\"");
</script>
</head>
<body>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -