我们可以通过JS修改元素的大小、颜色、位置等样式。
    1.element.style 行内样式操作
    2.element.className 类名样式操作

    注意:1.里面的属性名用驼峰命名法,如:background-color应写成backgroundColor
    2.JS修改style样式操作,产生的是行内样式,css权重比较高。

    1. <style><br /> div{<br /> width: 100px;<br /> height: 100px;<br /> background-color: pink;<br /> }<br /> </style><br /></head><br /><body><br /> <div></div><br /> <script><br /> //获取元素<br /> var div = document.getElementsByTagName('div');<br /> console.log(div);<br /> //绑定事件,处理程序<br /> var flag = 0;<br /> div[0].onclick = function () {<br /> // 里面的属性名用驼峰命名法<br /> if(flag == 0){<br /> this.style.backgroundColor = 'purple';<br /> this.style.width = '200px';<br /> this.style.height = '200px';<br /> flag = 1;<br /> }else{<br /> this.style.backgroundColor = 'pink';<br /> this.style.width = '100px';<br /> this.style.height = '100px';<br /> flag = 0;<br /> }<br /> }<br /> </script><br /></body>

    .