标签:
style.height书写方式与style[height] 书写等价 即.可与[]互换
可以用.的地方也可以用[],但是[]更好的地方在于可以用在函数传参
<script type="text/javascript"> function to(name,num){ var to=document.getElementById(‘div1‘); to.style[name]=num; } </script> </head> <body> <button onclick="to(‘backgroundColor‘,‘red‘)">变红</button> <button onclick="to(‘height‘,‘400px‘)">变高</button> <div id="div1"> </div> </body>
style加样式是在行间添加,取样式也是在行间取,如果样式写在外部文件,则style无效
标签:
原文地址:http://www.cnblogs.com/wyy725872/p/4497209.html