*javascript:使用对象保存数据
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<title>使用对象保存数据</title>
<body>
<!-- 代码放在body中,可运行 -->
<script type="text/javascript">
//自定义名片对象
function Card(name,address,telephone,work){
this.na=name;
this.ad=address;
this.tel=telephone;
this.wo=work;
this.printCard();
}
//扩展对象Card的printCard()方法
Card.prototype={
printCard:function(){
line1="<b>Name:</b>"+this.na+"<br>\n";
line2="<b>Address:</b>"+this.ad+"<br>\n";
line3="<b>Telephone:</b>"+this.tel+"<br>\n";
line4="<b>Work:</b>"+this.wo+"<br>\n";
document.write(line1,line2,line3,line4);
}
}
//测试
//创建Card对象
allen=new Card("吴冠中","中国广东省广州市","15626299383","著名画家");
</script>
</body>
结果如下: