遇到一件很奇怪的事情,javascript 本帖最后由 kobecsb 于 2013-04-19 20:30:34 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你在css里面加入javascript代码?这会不识别吧,虽然改过去了,可是会在被解析的时候忽略掉的。.edit{ background:red;}.edit:hover{ background:yellow;}.spanStyle{ background:AliceBlue;}.spanStyle:hover{ background:yellow;}把css改成这样试试,是不是你要的效果。 样式表里没有见过这么写的;js效果可以单独写js实现 .edit { background:red; onmouseout: expression(onmouseout=function (){this.style.backgroundColor = 'red'}); onmouseover: expression(onmouseover=function (){this.style.backgroundColor ='yellow'}); } .spanStyle{ onmouseout: expression(onmouseout=function (){this.style.backgroundColor ='AliceBlue'}); onmouseover: expression(onmouseover=function (){this.style.backgroundColor ='yellow'}); }不要在CSS里面写JS,把它去掉应该就可以了。 我的理解是这样的:css样式中,style里的样式比class的要优先,当你想通过改变class来改样式的时候,只要和style冲突,都不会现实该class的样式的。不知道对不对 反而是onmouseout和onmouseover可以实现,第一句的background:red无法实现 样式和js 分开,方便以后的维护,试试这种方法:<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title><style type="text/css">body,div{ margin:0px; padding:0px; }.edit{width:200px; height:200px; background:red;}.spanStyle{ background:AliceBlue}</style><script> function addColor(){ var edit = document.getElementById("editOne"); edit.className="edit"; edit.className= edit.className + ' spanStyle'; } function delColor(){ var edit = document.getElementById("editOne"); edit.className = "edit"; }</script></head> <body> <div class="edit" id="editOne" onmouseover="addColor()" onmouseout="delColor()">看我的变化</div></body></html> 问一个正则表达式的问题 js....pause 控制问题 div的属性问题 如何获取table中checkbox 选中行中列的数据? 在用JS实现实时计算的时候,为什么会出现对话框,提示"栈溢出"? 时间问题:给一个时间值,页面上显示该时间一秒一秒地自动跟谁服务器的时间递减 一个基础的问题 怎么样去掉IE的 滚动条和标题条? javascript问题 如何在innerHTML中加入超连接 这个正则的匹配如何写? javascript
background:red;
}
.edit:hover{
background:yellow;
}
.spanStyle{
background:AliceBlue;
}
.spanStyle:hover{
background:yellow;
}把css改成这样试试,是不是你要的效果。
js效果可以单独写js实现
background:red;
onmouseout: expression(onmouseout=function (){this.style.backgroundColor = 'red'});
onmouseover: expression(onmouseover=function (){this.style.backgroundColor ='yellow'});
}
.spanStyle{
onmouseout: expression(onmouseout=function (){this.style.backgroundColor ='AliceBlue'});
onmouseover: expression(onmouseover=function (){this.style.backgroundColor ='yellow'});
}不要在CSS里面写JS,把它去掉应该就可以了。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css">
body,div{ margin:0px; padding:0px; }
.edit{width:200px; height:200px; background:red;}
.spanStyle{ background:AliceBlue}
</style>
<script>
function addColor(){
var edit = document.getElementById("editOne");
edit.className="edit";
edit.className= edit.className + ' spanStyle';
}
function delColor(){
var edit = document.getElementById("editOne");
edit.className = "edit";
}
</script>
</head>
<body>
<div class="edit" id="editOne" onmouseover="addColor()" onmouseout="delColor()">看我的变化</div>
</body>
</html>