• 吴裕雄--天生自然 JAVASCRIPT开发学习:for 循环


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>        
    <body>
    
    <script>
    cars=["BMW","Volvo","Saab","Ford"];
    for (var i=0;i<cars.length;i++){
        document.write(cars[i] + "<br>");
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <p>点击按钮循环代码5次。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction(){
        var x="";
        for (var i=0;i<5;i++){
            x=x + "该数字为 " + i + "<br>";
        }
        document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    cars=["BMW","Volvo","Saab","Ford"];
    for (var i=0,l=cars.length; i<l; i++){
        document.write(cars[i] + "<br>");
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    cars=["BMW","Volvo","Saab","Ford"];
    var i=0,len=cars.length;
    for (; i<len; ){
        document.write(cars[i] + "<br>");
        i++;
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
        
    <p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction(){
        var x;
        var txt="";
        var person={fname:"Bill",lname:"Gates",age:56}; 
        for (x in person){
            txt=txt + person[x];
        }
        document.getElementById("demo").innerHTML=txt;
    }
    </script>
        
    </body>
    </html>

  • 相关阅读:
    HCNP Routing&Switching之BGP路由过滤和ASPathFilter Linux
    HCNP Routing&Switching之组播技术组播基础 Linux
    HCNP Routing&Switching之组播技术组播地址 Linux
    HCNP Routing&Switching之组播技术组播协议IGMP Linux
    HCNP Routing&Switching之BGP团体属性和团体属性过滤器 Linux
    pcanet网络理解
    OpenAPITools 实践
    React MobX 开始
    PDFium 渲染
    PDF.js Electron Viewer
  • 原文地址:https://www.cnblogs.com/tszr/p/10942402.html
Copyright © 2020-2023  润新知