第四章3

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用继承</title>
</head>
<body>
<div>
    <p>我是一只<span id="color"></span>的<span id="name"></span>,我已经<span id="age"></span>岁了,我有<span id="leg"></span>条腿</p>
    <script>
        function Animal(color,name,age) {
            this.color=color;
            this.name=name;
            this.age=age;
        }
        Animal.prototype.showColor=function () {
            return this.color;
        }
        Animal.prototype.showName=function () {
            return this.name;
        }
        Animal.prototype.showAge=function () {
            return this.age;
        }
        function Poultry(name,age,color,leg) {
            Animal.call(this,name,age,color);
            this.leg=leg;
        }
        Poultry.prototype=new Animal();
        Poultry.prototype.showLeg=function () {
            return this.leg;
        }
        var Poultry1=new Poultry("灰色","小狗狗","1","4");
        document.getElementById("color").innerHTML=Poultry1.showColor();
        document.getElementById("name").innerHTML=Poultry1.showName();
        document.getElementById("age").innerHTML=Poultry1.showAge();
        document.getElementById("leg").innerHTML=Poultry1.showLeg();
</script>
</div>
<div>
    <p>我是一只<span id="color1"></span>的<span id="name1"></span>,我已经<span id="age1"></span>岁了,我有<span id="leg1"></span>条腿</p>
    <script>
        function Animal1(color1,name1,age1) {
            this.color1=color1;
            this.name1=name1;
            this.age1=age1;
        }
        Animal1.prototype.showColor1=function () {
            return this.color1;
        }
        Animal1.prototype.showName1=function () {
            return this.name1;
        }
        Animal1.prototype.showAge1=function () {
            return this.age1;
        }
        function Poultry(name1,age1,color1,leg1) {
            Animal1.call(this,name1,age1,color1);
            this.leg1=leg1;
        }
        Poultry.prototype=new Animal1();
        Poultry.prototype.showLeg1=function () {
            return this.leg1;
        }
        var Poultry2=new Poultry("白色","茶杯猫","2","4");
        document.getElementById("color1").innerHTML=Poultry2.showColor1();
        document.getElementById("name1").innerHTML=Poultry2.showName1();
        document.getElementById("age1").innerHTML=Poultry2.showAge1();
        document.getElementById("leg1").innerHTML=Poultry2.showLeg1();
    </script>
</div>
<div>
    <p>我是一只<span id="color2"></span>的<span id="name2"></span>,我已经<span id="age2"></span>岁了,我有<span id="leg2"></span>条腿</p>
    <script>
        function Animal2(color2,name2,age2) {
            this.color2=color2;
            this.name2=name2;
            this.age2=age2;
        }
        Animal2.prototype.showColor2=function () {
            return this.color2;
        }
        Animal2.prototype.showName2=function () {
            return this.name2;
        }
        Animal2.prototype.showAge2=function () {
            return this.age2;
        }
        function Poultry(name2,age2,color2,leg2) {
            Animal2.call(this,name2,age2,color2);
            this.leg2=leg2;
        }
        Poultry.prototype=new Animal2();
        Poultry.prototype.showLeg2=function () {
            return this.leg2;
        }
        var Poultry3=new Poultry("红色","母鸡","1","2");
        document.getElementById("color2").innerHTML=Poultry3.showColor2();
        document.getElementById("name2").innerHTML=Poultry3.showName2();
        document.getElementById("age2").innerHTML=Poultry3.showAge2();
        document.getElementById("leg2").innerHTML=Poultry3.showLeg2();
    </script>
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值