怎么动态改变css style,程序怎么写才漂亮?
凡是类Class= "BBB "的,默认style= "A ",onMouseOver 时style= "B ",onMouseOut时style恢复 "A ".程序怎么写才好呢?
能不能设计一个类,指定默认style和替换style,并绑定事件?而不是生硬地这么写 <div style= " " onMouseOver= " " onMouseOut= " "> ?
------解决方案--------------------写两个class,A,B;
在你想更改的事件中,更改 <div> 的class.
------解决方案--------------------onMouseOver= "this.className= 'BBB ' " onMouseOut= "this.className= 'aaa ' ">
------解决方案--------------------用htc 应该可以实现
不过这个好像只有IE支持
------解决方案--------------------现在见过,不算太晚....
官方:
http://www.jquery.com
中文站:
http://jquery.org.cn
------解决方案--------------------style= "x "
x 是标准CSS语法...你干吗非要乱搞别的进去....
CSS可以用虚类解决...
:visited
:hover
:link
:active....
------解决方案-------------------- <style type= "text/css ">
.BBB {width:100px; height:100px; background:#f00; border:1px solid #00f;}
.B { width:100px; height:100px; background:#f00;}
.A { width:100px; height:100px; background:#00f;}
</style>
<div id= "wc " class= "BBB B "> </div>
<script type= "text/javascript ">
window.onload = function () {
var re = new Function( "a ", "b ", "this.className = this.className.replace(new RegExp(a + '$ '), b) ");
with (document.getElementById( "wc ")) {
onmouseover = function () { re.call(this, "B ", "A ") }, onmouseout = function () { re.call(this, "A ", "B ") };
}
}
</script>