JavaScript基础(javascript变量)

<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>


你可能感兴趣的:(JavaScript基础(javascript变量))