js对象 博客分类: 技术
程序员文章站
2024-03-19 11:21:46
...
<script language="javascript">
function people(age,name){
this.age =age;
this.name=name;
}
people.prototype.say=function(){
return "name:"+this.name+"age:"+this.age;
}
function create(){
var v1 =document.getElementById("v1").value;
var v2 =document.getElementById("v2").value;
var p =new people(v1,v2);
alert(p.say());
}
</script>
<body>
name:<input type="text" value="" id="v1" /><br/>
age :<input type="text" value="" id="v2" /><br/>
<input type="button" value="实例化" onclick="create()"/> <br>
</body>
function people(age,name){
this.age =age;
this.name=name;
}
people.prototype.say=function(){
return "name:"+this.name+"age:"+this.age;
}
function create(){
var v1 =document.getElementById("v1").value;
var v2 =document.getElementById("v2").value;
var p =new people(v1,v2);
alert(p.say());
}
</script>
<body>
name:<input type="text" value="" id="v1" /><br/>
age :<input type="text" value="" id="v2" /><br/>
<input type="button" value="实例化" onclick="create()"/> <br>
</body>
上一篇: 欧几里得算法求两个整数的最大公约数 博客分类: 技术
下一篇: 工作很累 博客分类: 个人