<div class="htmlarea"> <textarea id="runcode40600"> <title></title> <style type="text/css"> .class1{ background:#efefef; text-align:center; width:80px; } .class2{ background: #ffcc00; text-align:center; width: 80px; } .class3{ background: #ffffff; } .class4{ background: #ffff00; } </style> <table cellpadding="0" cellspacing="0" border="1" bordercolor="#cccccc" style="border-collapse:collapse" align="center" width="300"> <tr> <td t="yes">a</td> <td>this is section a</td> </tr> <tr> <td t="yes">b</td> <td>this is section b</td> </tr> <tr> <td t="yes">c</td> <td>this is section c</td> </tr> <tr> <td t="yes">d</td> <td>this is section d</td> </tr> </table> </textarea> <br> <input onclick="runEx('runcode40600')" type="button" value="运行代码"><input onclick="doCopy('runcode40600')" type="button" value="复制代码"><input onclick="doSave(runcode40600)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank"> </a>[Ctrl A 모두 선택 참고: </div>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 <script type="text/javascript"> function addEvent(elm, evType, fn, useCapture){ if (elm.addEventListener){ elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent){ var r = elm.attachEvent("on"+evType, fn); return r; } else { alert("Handler could not be removed"); } } function initTd(){ var sections=document.getElementsByTagName("td"); for(var i=0;i<sections.length;i++){ var section=sections[i]; if(section.getAttribute("t")=="yes"){ section.className="class1"; section.nextSibling.className="class3"; addEvent(section,"click",changeTd); } } } function changeTd(ev){ var ev=ev||window.event; var evt=ev.srcElement||ev.target; if(evt.tagName=="TD"&&evt.getAttribute("t")=="yes"){ var sections=document.getElementsByTagName("td"); for(var i=0;i<sections.length;i++){ var section=sections[i]; if(section.getAttribute("t")=="yes"){ section.className="class1"; section.nextSibling.className="class3"; evt.className="class2"; evt.nextSibling.className="class4"; } } } } </script>]<script type="text/javascript"> initTd(); </script>