style.backgroundColor="red"; //add
style.backgroundColor=""; //remove
style.backgroundColor=""; //remove
解决方案 »
- JSP动态增加一行,并实现 jquery autocomplete效果,怎么办?
- 淘宝商城1F,2F中排列图片是怎么实现的?
- onSubmit问题
- 大家来pk啦,数组组合算法,你最快的浏览器+你最快的程序能跑到多少
- 问个switch的
- 请问有没办法让网页浮标滚动到某个高度时就消失呢?
- jQuery的$(function(){...})怎么理解
- 请教如何用js将失去焦点的窗口关闭---谢谢!
- 如何改变字体的颜色?
- web页开始加载 正常 然后跳到其他页在按返回键回到原页面 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"/>
...