<tr onMouseOver="this.bgColor='red'" onMouseOut="this.bgColor='blue'" ...

解决方案 »

  1.   

    孟子E章大大,是的就是这种,不过
    关键是最后一点我没弄好。不会。
    就是当onMousedown时的状态。
    跟163.com邮局一样的一个选定状态时,input为选定。。再次input就取消,,背景色也回复到原来状态
      

  2.   

    <input type="checkbox" name="elements" id=="elements">如果才能是点一次选定,再点一次就取消了??<tr onMousedown="func1()" ></tr>function func1(){
        var a=document.getElementById("elements");
        if(a.checked == true){
            a.checked=false;     }else{
           a.checked=true;     }
    }
      

  3.   

    汗,没说清。。有多个一样的
    <input type="checkbox" name="elements" id="elements">
    不是只有一行。有很多行的
      

  4.   

    有很多行就遍历:
    <script>
      function change(){
      var obj = document.getElementsByName("elements")[0];
      if(obj.checked){
        color.bgColor = "#FFFFFF";
      }else{
        //不作操作
      }}
    </script>
    <table border='1'>
    <tr id="color" onMouseOver="this.bgColor='red'" onMouseOut="this.bgColor='blue'" onMousedown="this.bgColor='yellow'">
     <td>111111111</td><td><input type="checkbox" name="elements" onclick="change()"></td>
    </tr>
    </table>
      

  5.   

    function func1(){
        var a=document.getElementsByName("elements");
        for(i=0;i<a.length;i++){
            if(a[i].checked == true){
               a[i].checked=false;        }else{
               a[i].checked=true;         }
         }
    }
      

  6.   

    DeluxWorld(曾经的你)你这样是可行,不过还少了点,背景色选定后不是选定的颜色 mingxuan3000(铭轩) 可怎么才能知道我当前点选的哪个是哪一行啊。要不所有的都会变更了
      

  7.   

    当前点选的哪个是哪一行?
      if(a[i].checked == true){
               a[i].checked=false;  }
      

  8.   

    function func1(){
        var a=document.getElementsByName("elements");
        for(i=0;i<a.length;i++){
            if(a[i].checked == true){
               a[i].checked=false;        }     
        }
    }
      

  9.   

    我把代码贴出来帮我看看好不,,我总弄不好了
    <script type="text/javascript">
    var old_bg="";
    function inStyle(obj){  
    if(old_bg!="#FF0099") 
    { old_bg=obj.style.background;
    obj.style.background="#FFFF99";}}
    function DownStyle(obj){
    var e=document.getElementsByName("elements[]");
    for(i=0;i<e.length;i++){
    if(e[i].checked == true)
    {obj.style.background="#FF0099";old_bg="#FF0099";}
    else
    {obj.style.background=old_bg;
    }
         }
    }
    function outStyle(obj){
    obj.style.background=old_bg;}</script><table>
    <tr  onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
     <td>111111111</td><td><input type="checkbox" name="elements"></td>
    <td>111111111</td><td><input type="checkbox" name="elements"></td>
    <td>111111111</td><td><input type="checkbox" name="elements"></td>
    </tr>
    </table>
      

  10.   

    你说的是不是这样:
    <script type="text/javascript">
    var old_bg="";
    function inStyle(obj){  
    if(old_bg!="#FF0099") 
    { old_bg=obj.style.background;
    obj.style.background="#FFFF99";}}
    function DownStyle(obj){
    var e=document.getElementsByName("elements");
    for(i=0;i<e.length;i++){
    if(e[i].checked)
    {
     obj.style.background="#FF0099";
     //old_bg="#FF0099";
     break;
     }
    else
    {obj.style.background=old_bg;
    }
         }
    }
    function outStyle(obj){
    obj.style.background=old_bg;}</script><table>
    <tr  onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
     <td>111111111</td><td><input type="checkbox" name="elements"></td>
    <td>111111111</td><td><input type="checkbox" name="elements"></td>
    <td>111111111</td><td><input type="checkbox" name="elements"></td>
    </tr>
    </table>
      

  11.   

    是这样不?<table id="ice">
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    </table>
    <script type="text/javascript">
    var overBG = "#FFFF99";
    var outBG  = "#FFFFFF";
    var selBG  = "#FF0099";var tbl = document.getElementById("ice");
    var chk = document.getElementsByName( "elements[]");
    for(i=0;i<tbl.rows.length;i++)
    {
    tbl.rows[i].onmouseover = function(){
    this.style.background = overBG;
    }
    tbl.rows[i].onmouseout  = function(){
    var check = this.cells[1].childNodes[0];
    this.style.background =  check.checked == true ? selBG : outBG;
    }
    tbl.rows[i].onclick = function(){
    var check = this.cells[1].childNodes[0];
    this.style.background = check.checked == true ? selBG : overBG;
    }
    }
    </script>
      

  12.   

    才看到回复,那是这样了<table id="ice" style="cursor:default">
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    </table>
    <script type="text/javascript">
    var overBG = "#999";
    var outBG  = "#FFF";
    var selBG  = "#DDD";var tbl = document.getElementById("ice");
    var chk = document.getElementsByName( "elements[]");
    for(i=0;i<tbl.rows.length;i++)
    {
    tbl.rows[i].onmouseover = function(){
    this.style.background = overBG;
    }
    tbl.rows[i].onmouseout  = function(){
    var check = this.cells[1].childNodes[0];
    this.style.background =  check.checked == true ? selBG : outBG;
    }
    tbl.rows[i].onclick = function(){
    var check = this.cells[1].childNodes[0];
    check.checked = !check.checked;
    this.style.background = check.checked == true ? selBG : overBG;
    }
    }
    </script>
      

  13.   

    我改过了。。你看下效果
    <script type="text/javascript">
    var old_bg="";
    function inStyle(obj){  
    old_bg=obj.style.background;
    if(old_bg=="#ff0099")
    obj.style.background="#FF0099";
    else
    obj.style.background="#FFFF99";}
    function DownStyle(obj){
        var bgtrue=true;

    //var e=document.getElementsByName("elements[]");
    //e.checked=(e.checked?false:true);
    if(bgtrue)
    {
    if(obj.style.background=="#ff0099")
    {obj.style.background="";
    old_bg="";}
    else
    {obj.style.background="#FF0099";old_bg="#FF0099";bgtrue=false;
    }
    }
    else
    {obj.style.background=old_bg;
    }

    }
    function outStyle(obj){
    obj.style.background=old_bg;}</script>
    <table style="background:#eeeeee"> 
    <tr  onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
     <td>111111111</td><td><input type="checkbox" name="elements"></td></tr>
    <tr  onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee"><td>111111111</td><td><input type="checkbox" name="elements"></td></tr>
    <tr  onMouseOver="inStyle(this)" onMouseOut="outStyle(this)" onMouseDown="DownStyle(this)" style="background:#eeeeee">
    <td>111111111</td><td><input type="checkbox" name="elements"></td>
    </tr>
    </table>但我还要实现点行中任何位置多选框的选定与否也要相关
      

  14.   

    又改了一下,修改了点击checkbox不能改变状态的BUG<table id="ice" style="cursor:default">
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    <tr><td>111111111</td><td><input type="checkbox" name="elements[]"></td></tr>
    </table>
    <script type="text/javascript">
    var overBG = "#999";
    var outBG  = "#FFF";
    var selBG  = "#DDD";var tbl = document.getElementById("ice");
    var chk = document.getElementsByName( "elements[]");
    for(i=0;i<tbl.rows.length;i++)
    {
    tbl.rows[i].onmouseover = function(){
    this.style.background = overBG;
    }
    tbl.rows[i].onmouseout  = function(){
    var check = this.cells[1].childNodes[0];
    this.style.background =  check.checked == true ? selBG : outBG;
    }
    tbl.rows[i].onclick = function(e){
    var check = this.cells[1].childNodes[0];
    e = window.event || e;
    target = e.srcElement || e.target;
    if( target != check ) check.checked = !check.checked;
    this.style.background = check.checked == true ? selBG : overBG;
    }
    }
    </script>
      

  15.   

    ice_berg16(寻梦的稻草人)YES是这种效果。。
    我试下完了就结贴