zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVASCRIPT开发学习:对象

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var person=new Object();
    person.firstname="John";
    person.lastname="Doe";
    person.age=50;
    person.eyecolor="blue"; 
    document.write(person.firstname + " is " + person.age + " years old.");
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"}
    document.write(person.firstname + " is " + person.age + " years old.");
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    function person(firstname,lastname,age,eyecolor){
        this.firstname=firstname;
        this.lastname=lastname;
        this.age=age;
        this.eyecolor=eyecolor;
    }
    myFather=new person("John","Doe",50,"blue");
    document.write(myFather.firstname + " is " + myFather.age + " years old.");
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    <script>
    function person(firstname,lastname,age,eyecolor){
        this.firstname=firstname;
        this.lastname=lastname;
        this.age=age;
        this.eyecolor=eyecolor;
        this.changeName=changeName;
        function changeName(name){
            this.lastname=name;
        }
    }
    myMother=new person("Sally","Rally",48,"green");
    myMother.changeName("Doe");
    document.write(myMother.lastname);
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
        
    <p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction(){
        var x;
        var txt="";
        var person={fname:"Bill",lname:"Gates",age:56}; 
        for (x in person){
            txt=txt + person[x];
        }
        document.getElementById("demo").innerHTML=txt;
    }
    </script>
        
    </body>
    </html>

  • 相关阅读:
    spring事务传播机制实例讲解
    一篇关于交叉编译的文章
    Java中的泛型方法
    层序遍历打印二叉树
    寻找第K大 网易2016实习研发工程师编程题
    二叉树的非递归遍历
    二叉树 网易2016实习研发工程师编程题
    比较重量 网易2016实习研发工程师编程题
    网络地址为172.16.0.0,采用子网掩码255.255.224.0 .以下说法正确的是?
    2.7链表 回文链表
  • 原文地址:https://www.cnblogs.com/tszr/p/10944434.html
Copyright © 2011-2022 走看看