Ich habe diesen Artikel gesehen: 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>
Beispiel 2 hat diese Zeile: return arguments[0].style[arguments[1]];
Warum ist es nicht so geschrieben? return arguments[0].style.arguments[1];
Anstelle von Punkten [], Array verwenden?
.
运算符访问属性时,属性名是写定的,不能够根据表达式动态的生成属性名的.[]
运算符访问属性时,可以根据[]
里面的表达式动态生成属性名,得到属性名这个字符串.style.arguments[1]
相当于style['arguments'][1]