创建一个卡片对象,卡片上标有“名字”、“地址”和“电话”等信息。名片对象提供一个方法以输出这些信息。

<script type="text/javascript">
function Card(name, address, phone) {
this.name = name; //初始化名片信息
this.address = address;
this.phone = phone;
this.printCard = function() { //创建printCard函数的定义
line1 = "Name:" + this.name + "<br>\n"; //输出名片信息
line2 = "Address:" + this.address + "<br>\n"; //读取地址
line3 = "Phone:" + this.phone + "<br>\n"; //读取电话信息
document.writeln(line1, line2, line3); //输出
}
}
Tom = new Card("Tom", "hangzhouRoad 123", "0571-12345"); //创建Tom的名片
Tom.printCard(); //输出名片信息
</script>

posted @ 2015-07-06 11:10  程序猿凯  阅读(375)  评论(0编辑  收藏  举报