html:
<div id="box"></div>
css:
#box {
width: 100px;
height: 100px;
border: 1px solid #333;
}
js:
window.onload = function(){
var box = document.getElementById('box');
box.onclick = function(){
// box.style.width = '200px';
box.style.cssText = 'width:200px;height:200px;';//没有任何兼容性问题,这两个方法效果一样。
}
}
注意:
cssText添加的样式对原样式没有任何修改;
去除cssText样式,会恢复成原来的css样式。