//单选以及行变色
        function ClickCheck(id, ch) {
            var item = document.getElementById(ch);
            if (item.checked) {
                item.checked = false;
                document.getElementById(id).style.background = '#FFFFFF';
            } else {
                for (var l = 0; l < item.length; l++) {
                    if (item != item[l]) {
                        item[l].checked = false;
                        document.getElementById(id).style.background = '#FFFFFF';
                    }
                }
                item.checked = true;
                document.getElementById(id).style.background = '#99D1D3';
            }
        }
//checkNumber是一变量
<tr id="tr<%= checkNumber %>" onclick="ClickCheck(id,'Check<%=checkNumber %>');" style="cursor: pointer;">
//一个复选框
<input name="Item" id="Check<%=checkNumber %>" type="checkbox" onmousedown="ClickTr('tr<%= checkNumber %>',id);" />

解决方案 »

  1.   

    item != item[l]) ?
    怎么 这么写?
      

  2.   

    <script>
    //单选以及行变色
      function ClickCheck(id, ch) {
      var item = document.getElementById(ch);
      if (item.checked) {
      item.checked = false;
      document.getElementById(id).style.background = '#FFFFFF';
      } else {
      for (var l = 0; l < item.length; l++) {
      if (item != item[l]) {
      item[l].checked = false;
      document.getElementById(id).style.background = '#FFFFFF';
      }
      }
      item.checked = true;
      document.getElementById(id).style.background = '#99D1D3';
      }
      }
    </script>
    <table>
    <tr id="tr1" onclick="ClickCheck(id,'Check1');" style="cursor: pointer;"><td>sd</td></tr>
    </table>
    <input name="Item" id="Check1" type="checkbox" onmousedown="ClickTr('tr1',id);" />
      

  3.   

    呵呵,我也觉得挺怪的,不过不知者不罪,没写过JS,第一次,难免会犯些低级错误,因为对JS不是很深入的了解,我也是顺着想法写的,不知道该怎么搞!
      

  4.   

    LZ document.getElementById 不能返回数组function ClickCheck(id) {
      var item = document.getElementById(id);
      var oTr = item.parentElement;
      if (item.checked) {
          oTr.style.background = '#99D1D3';
      }else{
          oTr.style.background = '#FFFFFF';
      }
      }
    </script>
    <table>
    <tr id="tr" style="cursor: pointer;"><td>check</td><td>context</td></tr>
    <tr id="tr1" style="cursor: pointer;">
    <td><input name="Item" id="Check1" type="checkbox" onmousedown="ClickTr(id);" />
    </td>
    <td>sd</td>
    </tr>
    <tr id="tr2" style="cursor: pointer;"><td><input name="Item" id="Check2" type="checkbox" onmousedown="ClickTr(id);" />
    </td><td>sd</td></tr>
    <tr id="tr3" style="cursor: pointer;"><td><input name="Item" id="Check3" type="checkbox" onmousedown="ClickTr(id);" />
    </td><td>sd</td></tr>
    </table>
      

  5.   

    其实,我写那段代码要解决的问题是,当前选中行被选中,CheckBox也被选中,而其它所有的行如果有被选中的,都取消,CheckBox的Checked也为false!喔!对了,这个表格是循环出来的!每行都有CheckBox!