欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JavaScript基础(javascript变量)

程序员文章站 2022-03-02 11:53:36
...
<html>
    <head>
        <script type="text/javascript">
        function MyFunction(){
            var x = 5;
            var y = 6;
            var z = x + y;
            document.getElementById("hello").innerHTML = z;
        }
        </script>
    </head>
    <body>
        <p>Cal 5 + 6 = ?</p>
        <button type = "button" onclick="MyFunction()">Click!</button>
        <p id = "hello"></p>
        <script type="text/javascript">
            var car = new Array();
            var i;
            var j;
            var arr = new Array("test11","test22","test33");
            var testarr = {username:"name",password:"pass",type:"stu"};
            car[0] = "String one";
            car[1] = "String two";
            car[2] = "222";
            car[3] = "String three";
            for(i = 0 ; i < car.length ; i++){
                document.write(car[i]+",");
            }
            document.write("</br>");
            for(j = 0 ; j < arr.length ; j++){
                document.write(arr[j]+",")
            }
            document.write(testarr.username);
            document.write(testarr["password"]);
        </script>
    </body>
</html>


转载于:https://my.oschina.net/passer007/blog/602570