亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - A question about the value of js variable parameters
天蓬老師
天蓬老師 2017-06-26 10:51:16
0
2
821

Saw such an article: http://www.tuicool.com/articl...
Code snippet:

<script>
function css()
{
if(arguments.length==2) //獲取
{
return arguments[0].style[arguments[1]];
}
else
{
arguments[0].style[arguments[1]]=arguments[2];
}
}
window.onload=function ()
{
var op=document.getElementById('p1');
alert(css(op, 'width'));   //獲取width屬性值
css(op, 'background', 'green');
};
</script>
<p id="p1" style="width:200px; height:200px; background:red;"></p>

Example 2 has this line: return arguments[0].style[arguments[1]];
Why is it not written like this?
return arguments[0].style.arguments[1];
Instead of using dots, use [], array?

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進步~~

reply all(2)
ringa_lee

. When the operator accesses an attribute, the attribute name is written, and cannot dynamically generate the attribute name based on the expression. When the
[] operator accesses the attribute, can be based on [] The expression dynamically generates the attribute name and gets the attribute name string .

阿神

style.arguments[1] is equivalent to style['arguments'][1]

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template