zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    软件工程课感想
    冲刺阶段(二)第五天 5月19日
    CATransition转场动画
    UIView与CALayer的区别
    CALayer的基本属性
    CALayer的基本属性和contexts的内容 即添加图片
    Quartz2D-master手动截图
    CoreAnimation-06-CAKeyframeAnimation 相关代码
    CoreAnimation-06-CAKeyframeAnimation
    视频播放
  • 原文地址:https://www.cnblogs.com/wang01/p/10998811.html
Copyright © 2011-2022 走看看