<table>
  <tr>
    <td><input type="checkbox" name="checkbox1" id="checkbox1" />语文</td>
    <td><input type="checkbox" name="checkbox2" id="checkbox2" />数学</td>
  </tr>
</table>当选中checkbox时,将所在单元格的背景设置成淡黄色,字体设置为粗体!

解决方案 »

  1.   

    <table>
      <tr>
        <td><input type="checkbox" name="checkbox1" id="checkbox1" onclick="abc(this)"/>语文</td>
        <td><input type="checkbox" name="checkbox2" id="checkbox2" onclick="abc(this)"/>数学</td>
      </tr>
    </table><script>
    function abc(obj){
    if(obj.checked){
    obj.parentElement.style.backgroundColor="yellow";
    obj.parentElement.style.fontWeight="bold";
    }else{
    obj.parentElement.style.backgroundColor="";
    obj.parentElement.style.fontWeight="";
    }
    }
    </script>
      

  2.   

    能不能保持原来的代码不变用DOM来实现?
      

  3.   

    <table>
      <tr>
        <td><input type="checkbox" name="checkbox1" id="checkbox1" onclick="abc(this)"/>语文</td>
        <td><input type="checkbox" name="checkbox2" id="checkbox2" onclick="abc(this)"/>数学</td>
      </tr>
    </table><script>
    function abc(obj){
    if(obj.checked){
    obj.parentNode.style.backgroundColor="yellow";
    obj.parentNode.style.fontWeight="bold";
    }else{
    obj.parentNode.style.backgroundColor="";
    obj.parentNode.style.fontWeight="";
    }
    }
    </script>
    DOM?这样么?
      

  4.   

    <input type="checkbox" name="checkbox1" id="checkbox1" onclick="abc(this)"/>
    就是怎样不添加onclick事件来实现!
      

  5.   

    我的js很菜,就是问一下不添加onclick事件是否可以实现?
      

  6.   

    事件动态绑定么?window.onload=function(){
    var list = document.getElementsByTagName("input");
    for(var i=0; i<list.length; i++){
     var obj = list[i];
     if(obj.type="checkbox"){
      obj.onclick=function(){
       abc(event.srcElement);
      }
     }
    }
    }
      

  7.   

    如果不动态也行,
    将实例具体化。window.onload=function(){
    var checkbox1=document.getElementById("checkbox1");if (checkbox1.checked="checked"){
    checkbox1.parentNode.style.backgroundColor="yellow";
            checkbox1.parentNode.style.fontWeight="bold";}
    }
    最好用10楼的方法。