<td bgcolor="#666666">&nbsp;</td><td bgcolor="#666666">&nbsp;</td>  有很多这种小格子,我想鼠标双击改变bgcolor的值 ,是一定得改变的,因为还要保存到数据库里面的,请问要怎么弄好一点?

解决方案 »

  1.   

    <!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>
      

  2.   

    <!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>
    第二种方法!
      

  3.   

    谢谢你的回答,但是没有<td bgcolor="#666666">&nbsp;</td>  这个bgcolor属性,那我把表格提交到数据库再取出来还不是一样的?我是要存到数据库的,比如现在双击后是蓝色,我就要保存后取出来还是蓝色
      

  4.   

    你是用的什么控件啊???
    一定得是bgcolor吗???这样的东西一般不用自己编写的啊,如果要和数据库交互一般都是用别人写好的控件。要不然累死了了
      

  5.   

    不是了,我没有用控件,我有一张表格,把某些小格子的颜色弄好后,直接把整个表格的HTML代码保存到数据库,不是每双击一次就保存,所以才要实时双击的时候bgcolor的值 也跟着改变
      

  6.   

    那你等双击颜色改变了之后用js获取该div的html就好了嘛
      

  7.   

    <!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值改变了