返回目录
  • 更多资源请访问>>>BK设计资讯站(Www.Blue1000.Com)Www.Blue1000.Com
  • 主要解答:moonpiazza
  • 感谢:moonpiazza、liuzxit
  • 审核者:fason
  • 复选框与表格问题,谁帮我搞定?[高分]

  • -----------------------------------------------------------------------------------------

  • 修改了一下,去掉了对浏览器的兼容性,  
    希望还可以符合你的要求  
    在win2000  +  ie6.0(或5.0)测试通过  
     
    :_)  
    <html>  
    <head>  
    <title>Untitled  Document</title>  
    <meta  http-equiv="Content-Type"  content="text/html;  charset=gb2312">  
    </head>  
     
    <body>  
    <script  LANGUAGE="JavaScript">  
    var  checkflag="false";    
    var  theDefaultColor  =  '#ffffff';  
    var  thePointerColor  =  '#ccffcc';  
    var  theMarkColor  =  '#ffcc99';  
    function  check()  {    
               for  (var  i=0;i<listNews.elements.length;i++)  {  
                           var  Type=listNews.elements[i].type;  
                           var  name=listNews.elements[i].name;  
                           if  (Type=="checkbox"  &&  name.indexOf('censor')!=-1)  {  
                                         
                                       if  (listNews.elements[i].checked)    
                                       {  
                                                   newColor  =  theDefaultColor;                                                  
                                       }    
                                       else    
                                       {  
                                                   newColor  =  theMarkColor;              
                                       }  
                                       var  theCells  =  document.getElementById(i).cells;  
                                       var  rowCellsCnt    =  theCells.length;  
                                       for  (c  =  0;  c  <  rowCellsCnt;  c++)  
                                       {  
                                                   theCells[c].style.backgroundColor  =  newColor;  
                                       }  
     
                                       listNews.elements[i].checked=!listNews.elements[i].checked;  
                           }  
               }  
    }  
     
     
    /**  
     *  Sets/unsets  the  pointer  and  marker  in  browse  mode  
     *  
     *  @param      object        the  table  row  
     *  @param      interger    the  row  number  
     *  @param      string        the  action  calling  this  script  (over,  out  or  click)  
     *  @param      string        the  default  background  color  
     *  @param      string        the  color  to  use  for  mouseover  
     *  @param      string        the  color  to  use  for  marking  a  row  
     *  
     *  @return    boolean    whether  pointer  is  set  or  not  
     */  
    function  setPointer(theRow,  theRowNum,  theAction)  
    {  
     
     
                 
     
     
               //  3.  Gets  the  current  color...  
               var  theCells  =  theRow.cells;  
               var  rowCellsCnt    =  theCells.length;  
               var  currentColor  =  theCells[0].style.backgroundColor;  
               var  newColor          =  null;  
     
               //  4.  Defines  the  new  color  
               //  4.1  Current  color  is  the  default  one  
               if  (currentColor  ==  ''    ¦  ¦  currentColor.toLowerCase()  ==  theDefaultColor.toLowerCase())  
               {  
                           if  (theAction  ==  'over'  &&  thePointerColor  !=  '')  
                           {  
                                       newColor                            =  thePointerColor;  
                           }  
                           else  if  (theAction  ==  'click'  &&  theMarkColor  !=  '')  
                           {  
                                       document.getElementsByTagName("input")[theRowNum].checked  =!document.getElementsByTagName("input")[theRowNum].checked;  
     
                                       newColor                            =  theMarkColor;  
                           }  
               }  
               //  4.1.2  Current  color  is  the  pointer  one  
               else  if  (currentColor.toLowerCase()  ==  thePointerColor.toLowerCase()  )  
               {  
                           if  (theAction  ==  'out')  
                           {  
                                       newColor                            =  theDefaultColor;  
                           }  
                           else  if  (theAction  ==  'click'  &&  theMarkColor  !=  '')  
                           {  
                                       document.getElementsByTagName("input")[theRowNum].checked  =!document.getElementsByTagName("input")[theRowNum].checked;  
     
                                       newColor                            =  theMarkColor;  
                                         
                           }  
               }  
               //  4.1.3  Current  color  is  the  marker  one  
               else  if  (currentColor.toLowerCase()  ==  theMarkColor.toLowerCase())  
               {  
                           if  (theAction  ==  'click')  
                           {  
                                       document.getElementsByTagName("input")[theRowNum].checked  =!document.getElementsByTagName("input")[theRowNum].checked;  
                                         
                                       newColor            =  (thePointerColor  !=  '')  ?  thePointerColor  :  theDefaultColor;  
                           }  
               }  //  end  4  
     
               //  5.  Sets  the  new  color...  
               if  (newColor)  
               {  
                           var  c  =  null;  
     
                                       for  (c  =  0;  c  <  rowCellsCnt;  c++)  
                                       {  
                                                   theCells[c].style.backgroundColor  =  newColor;  
                                       }  
     
               }    
     
               return  true;  
    }  //  end  of  the  'setPointer()'  function  
     
    </script>  
    <form  name="listNews"  method="post"  action="">  
       <table  width="760"  border="1"  cellspacing="0"  cellpadding="0">  
           <tr>    
               <td  height="26"  align="center"  bgcolor="#CCCCCC"  onClick="check()"  style="cursor:hand">选择</td>  
               <td  colspan="2">&nbsp;</td>  
           </tr>  
           <tr  onmouseover="setPointer(this,  0,  'over');"  onmouseout="setPointer(this,  0,  'out');"  onmousedown="setPointer(this,  0,  'click');"  id="0">    
               <td  width="100"  height="26"  align="center">  <input  type="checkbox"  onClick="this.checked=!this.checked"  name=censor[0]  value=0></td>  
               <td  colspan="2">&nbsp;</td>  
           </tr>  
           <tr  onmouseover="setPointer(this,  1,  'over');"  onmouseout="setPointer(this,  1,  'out');"  onmousedown="setPointer(this,  1,  'click');"  id="1">    
               <td  width="100"  height="26"  align="center">  <input  type="checkbox"  onClick="this.checked=!this.checked"  name=censor[1]  value=0></td>  
               <td  colspan="2">&nbsp;</td>  
           </tr>  
           <tr  onmouseover="setPointer(this,  2,  'over');"  onmouseout="setPointer(this,  2,  'out');"  onmousedown="setPointer(this,  2,  'click');"  id="2">    
               <td  width="100"  height="26"  align="center">  <input  type="checkbox"  onClick="this.checked=!this.checked"  name=censor[2]  value=0></td>  
               <td  colspan="2">&nbsp;</td>  
           </tr>  
       </table>  
    </form>  
    </body>  
    </html>  
     


    返回目录