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?
ringa_lee2017-06-26 10:53:16
. 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 .