Blogger Information
Blog 18
fans 0
comment 0
visits 9970
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS中的循环,对象与函数05-06
偏执的博客
Original
584 people have browsed it

1.

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS循环,对象与函数</title>
    <script>
        // while 循环输出
        var user1 = [1,2,3,4,5,6,7,8,9];

        var i = 0;   //循环变量
        // 循坏开始
        while (i<user1.length) {
            // 数组元素%2,余数不等于0,就是奇数
            if (user1[i] % 2 !==0) {

                document.write(user1[i]);

            }
            i++;  // 更新条件 +1
        }
        document.write( "<br>");
       // 对象字面量花括号包裹起来非法的名称用引号包裹起来
        var user2 ={
            name:'一加7pro',
            battery:'4000mAh' ,
            cpu:' 骁龙855',
            screen:'6.67',
            price:'3999'


        };
        document.write('名字:'+user2.name+ "<br>");
        document.write('电池容量:'+user2.battery+ "<br>");
        document.write('处理器:'+user2.cpu+ "<br>");
        document.write('屏幕尺寸:'+user2.screen+ "<br>");
        document.write('价格:'+user2.price+ "<br>");

        // 函数表达式求三个数值之和
         var user3 = function(a,b,c) {
            var w=a+b+c;
             document.write('a+b+c='+w);
         }; // 匿名函数花括号末尾要加分号
        user3(9,99,999);

</script>
</head>
<body>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post