用JS怎样把一个表格的style的background设为空(即没有) style.backgroundColor="red"; //addstyle.backgroundColor=""; //remove 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ...<style type="text/css"><!--.red{ background-color:red;}--></style>...<div id="divTest" class="red">asdfasdfsdaf</div><input type="button" id="btnClassName" onclick="var a=document.getElementById('divTest');if(a.className=='red'){a.className='';}else{a.className='red';}" value="Change ClassName"/>... meizz(梅花雪)就是说赋空值就是移除,就会自动使用red 这个class了吧? 刚试过meizz(梅花雪)的方法, 不行, style.backgroundColor=""; //移除后背景色会变成白色, 而不是使用原来 class 指定的颜色的 可以通过改变样式表的color来实现~ DeluxWorld(曾经的你)具体怎样写法呢?还有能否取得className这个CSS里指定景背景色值,如果可以就可再用style 指定为这个值也可以 td.className = 'className'可以不? 做两套样式表,用className切换 xxuu503(我爱郭芙蓉!) 一开始就试过了, 而且还试过把className删除掉后再加上也不行 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><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 {TEXT-ALIGN: center;}#aa { background-color: #33CC66;}#center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; width: 700px; text-align: left;} --></style></head><script language="JavaScript" type="text/javascript">function aa(){ document.getElementById('ff').style.background = "#33CC66"; }</script><body><div id="center">dfffff</div><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td id="ff" style="background-color: #006666;"> </td> </tr></table><label><input type="button" onclick="aa();" name="Submit" value="按钮" /></label></body></html> ancomsj(fsdjfk)你是重设回原来的颜色值,问题是程序怎样取得css里设定的颜色值呀 我觉得没那么复杂吧,你在className里不要指定表格的背景色,而在style里指定,会不会更好些呢? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><style>.className { border: 1px solid #0000FF;}.className td{ border: 0px none none;}</style><body><script language="JavaScript" type="text/javascript">function changeBgColor(){ var tbl = document.getElementById("tbl_demo"); var defaultBackgroundColor = "#FF0000"; if (tbl.style.backgroundColor.toUpperCase() == defaultBackgroundColor.toUpperCase()){ tbl.style.backgroundColor = "#00FF00"; } else { tbl.style.backgroundColor = defaultBackgroundColor; }}</script><table id="tbl_demo" width="400" border="1" cellspacing="1" cellpadding="3" class="className" style="background-color:#FF0000;"> <tr> <td scope="row"> </td> <td> </td> </tr> <tr> <td scope="row"> </td> <td> </td> </tr></table><form id="form1" name="form1" method="post" action=""> <input type="button" name="Submit" value="变色" id="Submit" onclick="changeBgColor();" /></form></body></html> 把我上面的改改,不就完了么 ...<style type="text/css"><!--.red{background-color:red;}.green{background-color:green;}--></style>...<div id="divTest" class="red">asdfasdfsdaf</div><input type="button" id="btnClassName" onclick="var a=document.getElementById('divTest');if(a.className=='red'){a.className='green';}else{a.className='red';}" value="Change ClassName"/>... xeonwell(xeonwell) 如果是你这种方式就好办了, 但现在程序.red所指定的颜色是基色, 之后可以由用户自己来改颜色, 什么颜色是不定的, 给个选色器用户自己先, 所以用你的方法不行呀,如果是这样早就解决了KimSoft(革命的小酒天天醉)的方法还可以考虑下, 我开始也想过用公共变量保存这个色值,但这样深感就是不方便的,如果真的没办法也只有这样了 不方便之处在于我的页面有很多这样的表格, 每个表格用的css都不同, 所以颜色值也不同, 如果这样就要为每一个定义 一个全局变量,而且还要指定它是属于那个表格, 这样也是很头痛的事 解决了, 把CSS里所指定的颜色值读出来赋给当前的style就行了 为什么IE7下总提示" 缺少标识符、字符串或数字",其他浏览器均无问题 鼠标点击 切换li样式 一个链接怎么运行js啊 总是自动跳转 图片加载中的JS怎么写 怎么在点击链接显示层后 位置 不置顶 浏览器自动添加body 为什么是false?大家帮忙看看。 请教一段判断是否为浮点数和整数的正则表达式 请问怎样在网页中调用Word程序?? 在js中调用js文件如何能确保它立即运行? 表格被套上了CSS样式,就再也动态地改变不了了吗? 急!!!!请看一下,如果用js实现将excel表导入到网页中
<style type="text/css">
<!--
.red{
background-color:red;
}
-->
</style>
...
<div id="divTest" class="red">asdfasdfsdaf</div>
<input type="button" id="btnClassName" onclick="var a=document.getElementById('divTest');if(a.className=='red'){a.className='';}else{a.className='red';}" value="Change ClassName"/>
...
style.backgroundColor=""; //移除后背景色会变成白色, 而不是使用原来 class 指定的颜色的
一开始就试过了, 而且还试过把className删除掉后再加上也不行
<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 {TEXT-ALIGN: center;}
#aa {
background-color: #33CC66;
}
#center {
MARGIN-RIGHT: auto;
MARGIN-LEFT: auto;
width: 700px;
text-align: left;
}
-->
</style>
</head>
<script language="JavaScript" type="text/javascript">
function aa(){
document.getElementById('ff').style.background = "#33CC66";
}
</script><body>
<div id="center">dfffff</div>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td id="ff" style="background-color: #006666;"> </td>
</tr>
</table><label>
<input type="button" onclick="aa();" name="Submit" value="按钮" />
</label>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
.className {
border: 1px solid #0000FF;
}
.className td{
border: 0px none none;
}
</style>
<body>
<script language="JavaScript" type="text/javascript">
function changeBgColor(){
var tbl = document.getElementById("tbl_demo");
var defaultBackgroundColor = "#FF0000";
if (tbl.style.backgroundColor.toUpperCase() == defaultBackgroundColor.toUpperCase()){
tbl.style.backgroundColor = "#00FF00";
} else {
tbl.style.backgroundColor = defaultBackgroundColor;
}
}
</script><table id="tbl_demo" width="400" border="1" cellspacing="1" cellpadding="3" class="className" style="background-color:#FF0000;">
<tr>
<td scope="row"> </td>
<td> </td>
</tr>
<tr>
<td scope="row"> </td>
<td> </td>
</tr>
</table>
<form id="form1" name="form1" method="post" action="">
<input type="button" name="Submit" value="变色" id="Submit" onclick="changeBgColor();" />
</form>
</body>
</html>
<style type="text/css">
<!--
.red{
background-color:red;
}
.green{
background-color:green;
}
-->
</style>
...
<div id="divTest" class="red">asdfasdfsdaf</div>
<input type="button" id="btnClassName" onclick="var a=document.getElementById('divTest');if(a.className=='red'){a.className='green';}else{a.className='red';}" value="Change ClassName"/>
...