---恢复内容开始---

-----------

1.return

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数传参</title>
</head>
<body>
<script type="text/javascript">

function sum(a,b){

return a+b;

 

}
    alert(sum(6,7);
 
</script>

    
</body>
</html>

 

函数传参

----------------

arguments

                  ------可变参     不定参

arguments 传参求和

 fuction sum(){

var result=0;

for(var i=0; i<arguments.length;i++){

reslut+=arguments[i];

}

return result;

}

alert(sum(4,5,4));

 

--------------------------

css(oDiv ,'width')

 

 <DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>arguments</title>

</head>

<style>

#div1{

width:100px;

height:100px;

background:red;

}

</style>

<body>

<script type="text/javascript">

function css(object,name,value){

 if(arguments.length==2){

return object.style[name];

 

}

else{

object.style[name]=value;

}

 

}

window.onload=function(){

var oDiv=document.getElementsById('div1');

css(oDiv,'background','green');

 //alert(css(oDiv,'width'));

}

 

</script>

<div id="div1"></div>

</body>

</html>

第二种方法写

 

取非行间样式

currentStyle

<style>

</style>

<script>

window.onload=function(){

var oDiv=document.getElementById("div1");

alert("oDiv.currentStyle.width);

}

</script>

 

 

 

 

---恢复内容结束---