怎么动态改变css style,程序怎么写才漂亮? 写两个class,A,B;在你想更改的事件中,更改<div>的class. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 onMouseOver="this.className='BBB'" onMouseOut="this.className='aaa'"> 谢谢大家啊!hij333(我会改签名了.YEAH) ,syue(孤星)的想法可行,可是还是别扭啊。ssssssssssss能不能搞一个示范呢?您这么点到为止,我等还是云雾中人啊。哪位大师写段范例程序,最好是一个css类解决问题,实际元素只要 <div class="BBB">就可以了?? 凡是类Class="BBB"的,默认style="A",onMouseOver 时style="B",onMouseOut时style恢复"A".程序怎么写才好呢?能不能设计一个类,指定默认style和替换style,并绑定事件?而不是生硬地这么写<div style="" onMouseOver="" onMouseOut=""> ?jquery 一句就OK了....$(".BBB").mouseover(function(){ $(this).addClass("A").removeClass("B");}).mouseout(function(){ $(this).addClass("B").removeClass("A"); }); demo: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script><style> .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 class="BBB B"></div> <script type="text/javascript"> $(document).ready(function(){ $(".BBB").mouseover(function(){ $(this).addClass("A").removeClass("B");}).mouseout(function(){ $(this).addClass("B").removeClass("A"); }); }); </script> 用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> JS实现漂浮广告 正则表达式{n,m}的匹配,求解释 onkeyup应该怎么写才行??谢谢各位指点下----- innerHTML 中 双引号 问题 嵌入播放器的问题(javascript+dom)高手请进 一个小项目寻求合作,可能有后续项目,详情见附件,帮顶有分。 js中右击图片出现菜单 获取TD元素。。 javascript里的小问题,帮帮我,在线等。。。。(50) 如何操作JS对象 感觉没问题但就是运行不对的代码,请兄弟们看看 我用我最后的100分求一个验证文本框的javascript正则表达式!
ssssssssssss能不能搞一个示范呢?您这么点到为止,我等还是云雾中人啊。哪位大师写段范例程序,最好是一个css类解决问题,实际元素只要 <div class="BBB">就可以了??
能不能设计一个类,指定默认style和替换style,并绑定事件?而不是生硬地这么写<div style="" onMouseOver="" onMouseOut=""> ?
jquery 一句就OK了....$(".BBB").mouseover(function(){ $(this).addClass("A").removeClass("B");}).mouseout(function(){ $(this).addClass("B").removeClass("A"); });
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<style>
.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 class="BBB B">
</div> <script type="text/javascript">
$(document).ready(function(){
$(".BBB").mouseover(function(){ $(this).addClass("A").removeClass("B");}).mouseout(function(){ $(this).addClass("B").removeClass("A"); });
});
</script>
http://www.jquery.com中文站:
http://jquery.org.cn
x 是标准CSS语法...你干吗非要乱搞别的进去....CSS可以用虚类解决...
:visited
:hover
:link
:active....
.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>