请求帮助点击改变颜色值 <td bgcolor="#666666"> </td><td bgcolor="#666666"> </td> 有很多这种小格子,我想鼠标双击改变bgcolor的值 ,是一定得改变的,因为还要保存到数据库里面的,请问要怎么弄好一点? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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"> table{ cursor:pointer; } table td{ background-color:#FF0000; } .change{ background-color:#CCCCCC; }</style><script type="text/javascript">function douclick(btnobj){ btnobj.className = "change";}</script></head><body><table width="100px" height="40px"> <tr> <td id="line1" ondblclick="douclick(this)">aaa</td> <td id="line2" ondblclick="douclick(this)">bbb</td> </tr></table></body></html> <!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"> table{ cursor:pointer; } table td{ background-color:#FF0000; } .change{ background-color:#CCCCCC; }</style><script type="text/javascript">function douclick(btnobj,colorName){ //btnobj.className = "change"; btnobj.style.backgroundColor = colorName;}</script></head><body><table width="100px" height="40px"> <tr> <td id="line1" ondblclick="douclick(this,'black')">双击变黑</td> <td id="line2" ondblclick="douclick(this,'blue')">双击变蓝</td> </tr></table></body></html>第二种方法! 谢谢你的回答,但是没有<td bgcolor="#666666"> </td> 这个bgcolor属性,那我把表格提交到数据库再取出来还不是一样的?我是要存到数据库的,比如现在双击后是蓝色,我就要保存后取出来还是蓝色 你是用的什么控件啊???一定得是bgcolor吗???这样的东西一般不用自己编写的啊,如果要和数据库交互一般都是用别人写好的控件。要不然累死了了 不是了,我没有用控件,我有一张表格,把某些小格子的颜色弄好后,直接把整个表格的HTML代码保存到数据库,不是每双击一次就保存,所以才要实时双击的时候bgcolor的值 也跟着改变 那你等双击颜色改变了之后用js获取该div的html就好了嘛 <!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></head><body><div id="par"> <div id="t_div" style="width:100px; height:40px; background-color:#CCCCCC;"></div></div></body></html><script type="text/javascript"> alert(document.getElementById("par").innerHTML); document.getElementById("t_div").style.backgroundColor = "red"; alert(document.getElementById("par").innerHTML);</script>你看一下这个例子应该可以明白的会弹出id为t_div的div的html部分,注意其中的background-color值改变了 javascript 正则替换DIV标签 请问ajax如何提交特殊字符? 比如 +&之类的 Javascript漂浮框的问题 AJAX创建工具提示问题 请问在javascript中能否验证我输入的是英文还是中文? 怎么设置可以把dropdown设成可以输入数据?谢谢了哦! js高手请进(100 分) checkbox有没有onChange事件 javascript 报错,SCRIPT28: 堆栈溢出 jquery 使用$.each遍历数组的问题! js截取字符串 在线等,JS求助。
<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">
table{
cursor:pointer;
}
table td{
background-color:#FF0000;
}
.change{
background-color:#CCCCCC;
}
</style>
<script type="text/javascript">
function douclick(btnobj){
btnobj.className = "change";
}
</script>
</head><body>
<table width="100px" height="40px">
<tr>
<td id="line1" ondblclick="douclick(this)">aaa</td>
<td id="line2" ondblclick="douclick(this)">bbb</td>
</tr>
</table>
</body>
</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">
table{
cursor:pointer;
}
table td{
background-color:#FF0000;
}
.change{
background-color:#CCCCCC;
}
</style>
<script type="text/javascript">
function douclick(btnobj,colorName){
//btnobj.className = "change";
btnobj.style.backgroundColor = colorName;
}
</script>
</head><body>
<table width="100px" height="40px">
<tr>
<td id="line1" ondblclick="douclick(this,'black')">双击变黑</td>
<td id="line2" ondblclick="douclick(this,'blue')">双击变蓝</td>
</tr>
</table>
</body>
</html>
第二种方法!
一定得是bgcolor吗???这样的东西一般不用自己编写的啊,如果要和数据库交互一般都是用别人写好的控件。要不然累死了了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title></head><body>
<div id="par">
<div id="t_div" style="width:100px; height:40px; background-color:#CCCCCC;"></div>
</div>
</body>
</html>
<script type="text/javascript">
alert(document.getElementById("par").innerHTML);
document.getElementById("t_div").style.backgroundColor = "red";
alert(document.getElementById("par").innerHTML);
</script>你看一下这个例子应该可以明白的会弹出id为t_div的div的html部分,注意其中的background-color值改变了