zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    王妃
    某个奇怪的引理 学习总结
    多项式求ln,求exp,开方,快速幂 学习总结
    第二类斯特林数 学习总结
    cojs QAQ的图论题 题解报告
    cojs QAQ的序列 解题报告
    QAQ OI生涯の最后一个月
    cojs 疯狂的字符串 题解报告
    【51Nod 1238】最小公倍数之和 V3
    【51Nod 1190】最小公倍数之和 V2
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/11223006.html
Copyright © 2011-2022 走看看