点击事件给一个td设了背景,然后我想撤消我先行的动作回到前一个背景下,条件我不确定前面那个是什么背景!不知道大侠们有没有什么好方法试过<input type="reset">类似于reset的功能,但这个方法当前背景回不去

解决方案 »

  1.   

    你用什么方式设的背景用style么?建议用class方式的付值.重置后removeclass就行
      

  2.   

    这样的话用隐域这个方法就不是很合适了,window.history这个方法又不行.这个页没有前进后退历史..
      

  3.   

    <html>
        <head>
     <style type="text/css">
    .over{
    background:red;
    }
    .cur{
    background:blue;
    }
    </style>
            <script type="text/javascript">
                function over(o){
    o.oldClass = o.className;
        o.className = "over";
                 }
    function out(o){
    o.className = o.oldClass;
    }
            </script>
        </head>
        <body>
            <div style='width: 400px; height: 100px; cursor: pointer;' class="cur" onmouseover="over(this);" onmouseout="out(this);"></div>
        </body>
    </html>
      

  4.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>undoColor.html</title>

        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
         var colorAry = ["red", "blue", "green", "yellow", "white", "darkorchid"];
         var tempAry = [];
         function setColor(td) {
         var i = parseInt(Math.random()*(6)+1);  
         td.style.backgroundColor  = colorAry[i-1];
         tempAry.push(colorAry[i]);
         document.getElementById('c').innerHTML = tempAry.join(',');
         }
        
         function undoColor(td) {
         if (tempAry.length > 0) {
         td.style.backgroundColor = tempAry[tempAry.length - 1];
         tempAry.pop();
         } else {
         alert("最后一个了");
         }
         document.getElementById('c').innerHTML = tempAry.join(',');
         }
        </script>  </head>
      
      <body>
       <div id="c"></div>
         <table border="1">
         <tr>
         <td onclick="setColor(this)" id="t">改变</td>
         </tr>
         </table>
         <input type="button" value="undo" onclick="undoColor(document.getElementById('t'))"/>
      </body>
    </html>