JS 内置对象

什么是对象

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>什么是对象</title>
</head>
<body>
    <script>
        //people = new Object();
        //people.name = "aaa";
        //people.age = "20";
        //document.write("name:" + people.name + ",age:" + people.age);
    </script>

    <script>
        function people(name, age) {
            this.name = name;
            this.age = age;
        }
        son = new people("son", 32);
        document.write("name: " + son.name + ",age: " + son.age);
    </script>
</body>
</html>

2

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Date日期对象</title>
</head>
<body onload="startTime()">
    <script>
        function startTime() {
            var today = new Date();
            var h = today.getHours();
            var m = today.getMinutes();
            var s = today.getSeconds();
            m = checkTime(m);
            s = checkTime(s);
            document.getElementById("timeText").innerHTML = h + ":" + m + ":" + s;
            t = setTimeout(function () {
                startTime();
            }, 500);
        }

        function checkTime(i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }
    </script>
    <div id="timeText"></div>
</body>
</html>

3

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Array数组对象</title>
</head>
<body>

    <script>
        //var a = ["hello", "world"];
        //var b = ["iwen", "ime"];
        //var c = a.concat(b);
        //document.write(c);
        //var a = ["a", "c", "d", "t", "b", "e"];
        //var b = ["5", "2", "4", "3", "1", "6"];
        //document.write(a.sort());
        //document.write("<br/>");
        //document.write(b.sort());
        //document.write("<br/>");
        //document.write(a.sort(function (a, b) {
        //    return b - a;
        //}));

        var a = ["c", "b", "a"];
        document.write(a.reverse());
    </script>
</body>
</html>

 

posted @ 2019-07-21 22:03  一只桔子2233  阅读(113)  评论(0编辑  收藏  举报