• JavaScript对象及初识面向对象


    第一题
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>第一题</title>
    </head>
    <div id="intro"></div>
    <body>
    <script>
        var student=new Object();
        student.name="高乐乐";
        student.age="15";
        student.introduction="我叫高乐乐,我是一个初中三年级的学<br>生,我非常喜欢音乐和打篮球";
        student.intro=function () {
            var str="姓名:"+this.name+"<br>年龄:"+this.age+"<br>自我介绍:"+this.introduction;
            document.getElementById("intro").innerHTML=str;
        }
        student.intro();
    </script>
    </body>
    </html>
    第二题
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>第二题</title>
    </head>
    <body>
    <div>
        <p>姓名:<span id="name"></span></p>
        <p>年龄:<span id="age"></span></p>
        <p>自我介绍:<span id="intro"></span></p>
        <script>
            function Person(name,age){
                this.name=name;
                this.age=age;
            }
            Person.prototype.showName=function(){
                return this.name;
            }
            Person.prototype.showAge=function () {
                return this.age;
            }
            function Student(name,age,intro){
                Person.call(this,name,age);    //继承属性
                this.intro=intro;
            }
            Student.prototype=new Person();
            Student.prototype.showIntro=function () {
                return this.intro;
            }
            var Student1=new Student("王小明",16,"我是高中一年级的学生,身高1.8米,很帅,我喜欢学习语文和英语。");
            document.getElementById("name").innerHTML=Student1.showName();
            document.getElementById("age").innerHTML=Student1.showAge();
            document.getElementById("intro").innerHTML=Student1.showIntro();
        </script>
    </div><br>
    <div>
        <p>姓名:<span id="name1"></span></p>
        <p>年龄:<span id="age1"></span></p>
        <p>自我介绍:<span id="intro1"></span></p>
        <script>
            function Person(name1,age1){
                this.name1=name1;
                this.age1=age1;
            }
            Person.prototype.showName1=function(){
                return this.name1;
            }
            Person.prototype.showAge1=function () {
                return this.age1;
            }
            function Student(name1,age1,intro1){
                Person.call(this,name1,age1);    //继承属性
                this.intro1=intro1;
            }
            Student.prototype=new Person();
            Student.prototype.showIntro1=function () {
                return this.intro1;
            }
            var Student1=new Student("黄妞妞",6,"我今年6岁了,非常可爱,马上就可以上小学了,就可能有好多好多的小朋友了。");
            document.getElementById("name1").innerHTML=Student1.showName1();
            document.getElementById("age1").innerHTML=Student1.showAge1();
            document.getElementById("intro1").innerHTML=Student1.showIntro1();
        </script>
    </div>
    </body>
    </html>
  • 相关阅读:
    IO流2 --- File类的常用方法1 --- 技术搬运工(尚硅谷)
    IO流1 --- File类的实例化 --- 技术搬运工(尚硅谷)
    luoguP6136 【模板】普通平衡树(数据加强版)
    CF981E Addition on Segments 线段树分治+bitset
    LOJ#2538. 「PKUWC2018」Slay the Spire DP+组合
    LOJ#2537. 「PKUWC2018」Minimax 线段树合并
    luoguP4220 [WC2018]通道 随机化
    学习笔记2018/6/22
    git push解决办法: ! [remote rejected] master -> master (pre-receive hook declined)
    IDEA错误:Cannot start compilation: the output path is not specified for module "Test". Specify the out
  • 原文地址:https://www.cnblogs.com/wang01/p/10998811.html
Copyright © 2020-2023  润新知