复选框怎么给小框添加背景色?

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>复选框选中后改变背景色-80端口</title>
    <script type="text/javascript">
    function chaCloor(field){
    var pig = field.checked;
    pig?field.parentNode.style.backgroundColor="yellow":field.parentNode.style.backgroundColor="";
    }
    </script>
    </head><body>
    <ul>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项1</li>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项2</li>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项3</li>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项4</li>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项5</li>
     <li><input type="checkbox" onClick="chaCloor(this);" />选项6</li>
    </ul>
    </body>
    </html>