改变行的颜色
function changebgcolor(obj){
obj.style.backgroundColor = '#ff0000';
}...
<tr onclick="changebgcolor(this);">
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
</tr>
...至于什么时候显示什么颜色自己在用程序控制一下

解决方案 »

  1.   

    或者是LZ把各个颜色写成css样式,onclick的时候调用样式,如:
    <style type="text/css">
    <!--
    .STYLE1 {color: #FF0000}
    -->
    </style>document.getElementById("div").className = "STYLE1";
      

  2.   

    我問的不是這個效果...我問的是:表格行的顯示與隱藏問題...不好意思...怪我沒說清楚...就是當我點擊紅色那行的checkbox,下面那行黑色的就顯示出來..如果再點擊一次,黑色的那行又隱藏起來....這個意思....這次應該明白了吧....下面那些同理...就是當點擊黑色行的checkbox時紫色的那行顯示,再次點擊紫色行又隱藏起來....
      

  3.   

    都是一个道理,就是触发某事件改变某个元素的CSS属性,隐藏就是~.style.display。
    楼主字能打简体的么?繁体看着特累。
      

  4.   


    <!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=utf-8" />
    <title><?=$info['supplyname']?>供應商品列表</title>
    <link href="../css/supplystyle1.css" rel="stylesheet" type="text/css" />
    <script src="../css/suplly.js"></script>
    <script>
    function showHide(id){
    //for(var i=document.all.query.rows.length;i>=0;i--) 
           // if(i%2==0)   
              // document.query.rows[i].style.display="none";


       var i=document.all.query.tBodies.length;
      
       var traget=document.getElementById(id);
       
           if(traget.style.display=="none"){
             traget.style.display="";
           }else{
             traget.style.display="none";
         }
    }
    </script>
    </head>
    <body>
    <div align="center" id="formwrapper"><form action="<? echo $PHP_SELF;?>" method="post" name="form1"><label for="condition">請選擇條件:</label>
    <select name="select">
      <option value="typename">商品種類</option>
      <option value="supplyname">供應商名稱</option>
    </select>
    <input name="content" type="text" />
    <input name="submit" type="submit" class="buttom" value="搜索" />
    <input type="button" class="buttom" value="返回" onclick="location.href='../suppliers/supplylist.php';" /></form></div>
    <?
      $select=$_POST['select'];
      $content=$_POST['content'];
    ?>
    <h3 align="center" style="margin-top:0px;">
    與<font color="#FF3399">[<? echo $content;?>]</font>相符合商品
    </h3>
    <form action="#" method="post">
    <table align="center" id="query">
    <thead>
      <tr>
        <th width="5%"></th>    
        <th width="12%">供應商</th>   
        <th width="15%">聯系人</th>
        <th width="22%">聯系電話</th>
        <th width="20%">聯系地址</th>
        <th width="26%">電子郵件</th>
      </tr>
      <tr>
        <th width="5%"></th>
        <th width="12%"></th>
        <th width="15%">商品名稱</th>
        <th width="22%">商品價格</th>
        <th width="20%">報價時段</th>
        <th width="26%">是否采購</th>  
      </tr>
      <tr>
        <th width="5%"></th>
        <th width="12%"></th>
        <th width="15%"></th>
        <th width="22%">采購單編號</th>
        <th width="20%">采購日期</th>
        <th width="26%">交易貨幣</th>  
      </tr>
    </thead>
    <tbody>
    <?
        $pg = @$_REQUEST["pg"]; //接收当前的页码。
        $pagelist =10; //设定每页显示10条记录
        $limitFrom = 0; //开始limit的数,用于当前pg(即页码)小于2的场合。此时sql的语句为..... limit 0,10
        if (!isset($pg))
        {                //如果接收的页码为空,说明当前为第一页。
             $pg = 1;    //把页码设定为第一页
        }
        if ($pg>1){ //当页码大于1 的时候,需要设定limitFrom。此时sql可能为 limit 30,10
             $limitFrom = $pagelist*($pg-1);    //这是个计算limitFrom小算法,仔细看看就能明白了。
        }else{
             $limitFrom = 0;
        }

    if($select=="typename"){
    $sql="select * from $DB_NAME1._itemtypeinfo where typename like '%".$content."%' and _itemtypeinfo.state!=1 ";
    }
    else if($select=="supplyname"){ 
    $sql="select * from _suppliersinfo,_purchasegoodsinfo,_goodspriceinfo,
          _itemtypeinfo where 
     _itemtypeinfo.id=_suppliersinfo.tid and 
     _purchasegoodsinfo.tid=_itemtypeinfo.id and 
     _purchasegoodsinfo.sid=_suppliersinfo.id and 
     _goodspriceinfo.gid=_purchasegoodsinfo.id and 
     _suppliersinfo.supplyname like '%".$content."%' group by supplyname order by   
     $DB_NAME1._goodspriceinfo.price+0 asc LIMIT ".$limitFrom.",".$pagelist;
    }
    else{
    $sql="select * from _itemtypeinfo,_suppliersinfo,_purchasegoodsinfo,
         _goodspriceinfo  where 
     _itemtypeinfo.id=_suppliersinfo.tid and 
     _purchasegoodsinfo.tid=_itemtypeinfo.id and 
     _purchasegoodsinfo.sid=_suppliersinfo.id and 
     _goodspriceinfo.gid=_purchasegoodsinfo.id  
     group by supplyname order by $DB_NAME1._goodspriceinfo.price+0 asc LIMIT ".$limitFrom.",".$pagelist;
    }
    $result=mysql_query($sql) or die("SQL Error: <br>".$sql."<br>".mysql_error());
    $count=mysql_num_rows($result);
    if($count!=0){  
    while($row=mysql_fetch_array($result)){
        $query1="select * from $DB_NAME1._suppliersinfo where tid=".$row['id'];
        $info1=mysql_query($query1) or die("Suppliers Error:<br>".mysql_error());
        while($row1=mysql_fetch_array($info1)){
    ?>
      <tr>
        <td><input type="checkbox" name="select[]" value="" onclick="showHide('menu')" /></td>
        <td><font color="#FF0000"><?=$row1['supplyname']?></font></td>
        <td><font color="#FF0000"><?=$row1['contact1']."/".$row1['contact2']?></font></td>
        <td><font color="#FF0000"><?=$row1['tel1']."/".$row1['tel2']."/".$row1['tel3']."/".$row1['tel4']?></font></td>
        <td><font color="#FF0000"><?=$row1['address']?></font></td>
        <td><font color="#FF0000"><?=$row1['email']?></font></td>
      </tr>
      <?
          $query2="select * from $DB_NAME1._purchasegoodsinfo where sid=".$row1['id']." and state!=1";
          $info2=mysql_query($query2) or die("Goods Error:<br>".mysql_error());
          $count2=mysql_num_rows($info2);
      while($row2=mysql_fetch_array($info2)){
      $query4="select * from $DB_NAME1._goodspriceinfo where gid=".$row2['id']." and state!=1 ";
      $row4=mysql_fetch_array(mysql_query($query4));
      ?>
      <tr id="menu">
        <td width="5%">&nbsp;</td>
        <td width="12%"><input type="checkbox" name="select[]2" value="" onclick="showHide('menu1')" /></td>
        <td width="15%"><?=$row2['goodsname']?></td>
        <td width="22%"><?=$row4['price']?></td>
        <td><?=$row4['startdate']?>至<?=$row4['enddate']?></td>
        <td><input type="button" value="采購" name="button" onclick="location.href='../purchaselist/purchaselistinput.php?gid=<?=$row4['gid']?>'"/></td>
      </tr>
      <?         $query3="select * from $DB_NAME1._purchaselistinfo where gid=".$row2['id']." and state!=1";
             $info3=mysql_query($query3) or die("Query Error:<br>".$query.mysql_error());
             $con3=mysql_num_rows($info3);
             while($row3=mysql_fetch_array($info3)){  
      ?>
      <tr id="menu1" style="display:none;">
        <td width="5%">&nbsp;</td>
        <td width="12%">&nbsp;</td>
        <td width="15%"><input type="checkbox" name="select[]3" value="" /></td>
        <td width="22%"><font color="#5500FF"><? echo $row3['listno'];?></font></td>
        <td><font color="#5500FF"><? echo $row3['date'];?></font></td>
        <td><font color="#5500FF"><? echo $row3['currency'];?></font></td>
      </tr>
    <?
              }
            }
          }
        }
       }
       else{
    ?>
      <tr>
       <td colspan="6"><font color="blue">很抱歉,沒有相關的資料.</font></td>
      </tr>
    <?    
       }
    ?>
    </tbody>
      <tr>
       <td colspan="6"><div align="center"><?php $pager = new Pager($countAll,$pagelist);?></div></td>
      </tr>
    </table>
    <div align="left">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" value="全選" name="chkall" onclick="CheckAll(this.form)"/>
    <input type="button" value="反選" name="chkothers" onclick="CheckOthers(this.form)"/>
    <input type="submit" name="submit" value="列印選中" />
    </div>
    </form>
    </div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>我的代碼和js都在這了...幫我看看吧....thanks
      

  5.   

    就是加个JS函数吧function showHide(obj,id){
    var obj = document.getElementById(id);
    obj.style.display = obj.checked?'','none';
    }
    这样调用<td><input type="checkbox" name="select[]" value="" onclick="showHide(this,'menu')" /></td>
      

  6.   

    就是加个JS函数吧function showHide(oThis,id){
    var obj = document.getElementById(id);
    obj.style.display = oThis.checked?'','none';
    }
    这样调用<td><input type="checkbox" name="select[]" value="" onclick="showHide(this,'menu')" /></td>
      

  7.   

    你可以用JavaScript的OnClick事件,当Click就改变一个元素的STYLE属性,也可以改变它的CSS,就可以了啊。呵呵,楼上的,有同感啊!繁体看得像英语那样累。
      

  8.   

    老韩...你那个有错唉...老是报什么 excepted:,是不是你的这个应该改成 ":"啊?oThis.checked?'','none';
      

  9.   

    display设置成空字符串的话,有时候会被某些全局CSS覆盖,所以还是指定具体的值吧。
      

  10.   


    是我用的display啊...但是只能控制第一个....其他行的id根本没有控制到...高手...怎样让他遍历行的id并且各自行控制各自下面的行呢?
      

  11.   


    也是指定ID,谁display了,哪个就不见了,如果一个元素包含几个子元素,那么也就全部隐藏了啊,又或者是一个个的隐藏,反正就是指定ID的属性,设置一下。
      

  12.   

    对,我写错了,呵 codeoThis.checked?'':'none';
      

  13.   

    把纯html,js代码贴出来,自己归纳问题,做个简单table,尽量问题简单化,把php代码sql语法都处理掉,不要贴出来,这样问问题实在很....