JS 面向对象

来源:互联网 发布:话费查询软件 编辑:程序博客网 时间:2024/06/07 18:14

Person.js

function Person(name,age){//|构造this.name=name;this.age=age;//|方法this.show=function(){alert(this.name+"+"+this.age);}//|带参数的方法this.showstr=function(str){alert(str);}//|设置this.setName=function(str){this.name=str;}}
index.html

<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><script type="text/javascript" src="js/Person.js" ></script><script>window.onload=function(){var p=new Person("邱于涵",11);p.show();p.showstr("xx");p.setName("涵涵");p.show();}</script></head><body></body></html>



0 0