【代码笔记】Web-JavaScript-Javascript对象

一,效果图。

二,代码。

复制代码
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>javascript 对象</title>
</head>

<body>
    <p>创建javascript对易县.</p>
    <p id="demo"></p>
    <script type="text/javascript">
    var person = {
        firstname: "john",
        lastname: "doe",
        age: 50,
        eyecolor: "blue"

    };

    document.getElementById("demo").innerHTML = person.firstname + "is" + person.age + "years old";
    </script>
    <p>创建和使用对象方法。</p>
    <p>对象方法作为一个函数定义存储在对象属性中。</p>
    <p id="demo"></p>
    <script>
    var person = {
        firstName: "John",
        lastName: "Doe",
        id: 5566,
        fullName: function() {
            return this.firstName + " " + this.lastName;
        }
    };

    document.getElementById("demo").innerHTML = person.fullName();

    < /body>

    < /html>
复制代码

 

 

参考资料:《菜鸟教程》

posted @ 2018-12-05 09:06  花儿迎风笑  阅读(323)  评论(0编辑  收藏  举报