學習JavaScript

darkchii發表於2017-09-01
    隨便看了看JavaScript的基礎,因為基礎都挺簡單,就直接用我們程式設計師最熟悉的打招呼方式來進行第一次的輸出。
    還是個菜鳥,如果有格式上的問題或者不正確之處還望看客能不吝賜教!謝謝!
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"> 
</head>

<body>

    <p id = "demo0"></p>
    <p id = "demo1"></p>

    <script>
        //變數物件
        var person = {
            firstName: "hello",
            lastName : "world",
        };
        document.getElementById("demo0").innerHTML = 
            person.firstName + " " + person.lastName + "!";

        var person = {
            firstName: "hello",
            lastName : "world",

            fullName : function()
            {
                return this.firstName + " " + this.lastName + "!";
            }
        };
        var x = person.firstName.length
        var y = person.lastName.length
        var z = x + y + 2
        document.getElementById("demo1").innerHTML = person.fullName();
        document.write("<p>" + "字串長度為:" + z + "</p>");
    </script>

</body>
</html>

相關文章