js参数求和和参数取值,设置值

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>参数求和和参数取值,设置值</title>
<script>
function result(){
var result=0;
for(var i=0;i<arguments.length;i++){
result+=arguments[i];
}
return result;
}
//alert(result(7,8,9999,1,2,34));
//
// function css(){
// if(arguments.length==2){
// return arguments[0].style[arguments[1]];
// }else{
// arguments[0].style[arguments[1]]=arguments[2];
// }
// }

function css(obj,name,value){
if(arguments.length==2){
return obj.style[name];
}else{
obj.style[name]=value;
}
}


window.onload=function(){
var div1=document.getElementById("div1");
// alert(css(div1,"width"));
css(div1,'width',"200px")
}
</script>
</head>
<body>
<div id="div1" style="width:100px;height: 100px;background: red;"></div>
</body>
</html>

posted @ 2018-09-02 18:11  quitpoison  阅读(154)  评论(0)    收藏  举报