[读码时间] arguments应用,求参数总和

说明:代码取自网络,注释为笔者学习时添加

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>arguments应用,求参数总和</title>
    <style>
        pre{
            color:green;
            padding:10px 15px;
            background:#f0f0f0;/*灰白色*/
            border:1px solid #333;/*黑色*/
            font:12px/1.5 Courier New;/*行高18*/
        }
        span{
            color:#999;/*浅黑色*/
        }
    </style>
</head>
<body>
    <pre>
        &lt;script type="text/javascript"&gt;
    var i = iResult = 0
    function sum()
    {
        for (var i = 0; i < arguments.length; i++)
        {
            iResult += arguments[i]
        }
        return iResult
    }
        <span>//应用</span>
    alert(sum(1,2,3,4,5,6,7,8,9,10)) <span>//输出55</span>
&lt;/script&gt;
</pre>
    <script>
        var i = iResult = 0;
        function sum() {
            for (var i = 0; i < arguments.length; i++) {
                iResult += arguments[i];
            }
            return iResult;
        }
        alert(sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
    </script>
</body>
</html>
View Code

 

posted @ 2017-03-02 02:14  sx00xs  阅读(133)  评论(0编辑  收藏  举报