日期:2014-05-16 浏览次数:20365 次
<input type=checkbox name=ztid[] id='check2' value='2'><label for='check2'>高考</label> <br><input type=checkbox name=ztid[] id='check3' value='3'><label for='check3'>作文</label> <br><input type=checkbox name=ztid[] id='check30' value='30'><label for='check30'>零分作文</label> <br><input type=checkbox name=ztid[] id='check31' value='31' checked><label for='check31'>满分作文</label>
<!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>无标题文档</title> <script type="text/javascript"> window.onload = function() { var oLabels = document.getElementsByTagName('label'); for (var i = 0; i < oLabels.length; i ++) { if (document.getElementById(oLabels[i].getAttribute('for')).checked) oLabels[i].style.backgroundColor = '#FF0'; //初始化label背景色 oLabels[i].onclick = function() { var chkbox = document.getElementById(this.getAttribute('for')); if (chkbox.checked) this.style.backgroundColor = '#FFF'; else this.style.backgroundColor = '#FF0'; } } var o = document.getElementsByName('ztid[]'); for (var i = 0; i < o.length; i ++) { o[i].onclick = function() { var oNext = this.nextSibling; while (oNext.nodeType != 1) oNext = oNext.nextSibling; if (this.checked) oNext.style.backgroundColor = '#FF0'; else oNext.style.backgroundColor = '#FFF'; } } } </script> </head> <body> <input type=checkbox name=ztid[] id='check2' value='2'> <label for='check2'>高考</label> <br> <input type=checkbox name=ztid[] id='check3' value='3'> <label for='check3'>作文</label> <br> <input type=checkbox name=ztid[] id='check30' value='30'> <label for='check30'>零分作文</label> <br> <input type=checkbox name=ztid[] id='check31' value='31' checked> <label for='check31'>满分作文</label> </body> </html>