HTML
<pre>
<script >
var i = iResult = 0
function sum()
{
for (var i=0; i < arguments.length; i++)
{
iResult += arguments[i]
}
return iResult
}
<span>alert(sum(1,2,3,4,5,6,7,8,9,10))</span>
<script>
</pre>
<pre>
標(biāo)簽, 在頁面上顯示代碼
<
做尖括號 , >
右尖括號
JS
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))
arguements
是傳遞給函數(shù)的參數(shù)的類數(shù)組對象, 是所有非箭頭函數(shù)中都可用的局部變量