怎么用onclick事件设置css中的属性

如题所述

第1个回答  2012-03-12
1楼太麻烦了吧。。直接onclick="this.style.background='#fff'"> style后面的属性自己更换
第2个回答  2012-03-12
例子1:
html代码:
<div style="cursor:pointer;width:100px;height:100px;" onclick="this.style.background='red';">点我</div>

例子2:
js代码:
function changeStyle(obj){
obj.style.background='red';
}
html代码:
<div style="cursor:pointer;width:100px;height:100px;" onclick="changeStyle(this)">点我</div>
相似回答