<div class="htmlarea"> <textarea id="runcode288"> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content="majianan"> <meta name="Keywords" content=""> <meta name="Description" content=""> <script type="text/javascript"><!-- function swapNode(node1,node2) { var _parent=node1.parentNode; var _t1=node1.nextSibling; var _t2=node2.nextSibling; if(_t1) _parent.insertBefore(node2,_t1); else _parent.appendChild(node2); if(_t2) _parent.insertBefore(node1,_t2); else _parent.appendChild(node1); } function swap(){ var t1 = document.getElementById("t1").value; var t2 = document.getElementById("t2").value; swapNode(document.getElementById(t1),document.getElementById(t2)); } // --></script> <table> <tr> <td id="a">[a]</td> <td id="b">[b]</td> <td id="c">[c]</td> <td id="d">[d]</td> <td id="e">[e]</td> </tr> </table> <tr><td><input id="t1" type="text" value="a"></td></tr> <tr><td><input id="t2" type="text" value="b"></td></tr> <tr><td><input type="button" value="swap" onclick="swap()"></td></tr> </textarea><br><input onclick="runEx('runcode288')" type="button" value="运行代码"> <input onclick="doCopy('runcode288')" type="button" value="复制代码"> <input onclick="doSave(runcode288)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>上面的格式,比较奇怪,我用js稍微改了下,文本框分别是要转换的索引,不能随便输。<br><div class="htmlarea"> <textarea id="runcode92002"> <meta content="text/html;charset=gb2312" http-equiv="Content-Type"> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content="majianan"> <meta name="Keywords" content=""> <meta name="Description" content=""> <script type="text/javascript"><!-- function swapNode(node1,node2) { var _parent=node1.parentNode; var _t1=node1.nextSibling; var _t2=node2.nextSibling; if(_t1) _parent.insertBefore(node2,_t1); else _parent.appendChild(node2); if(_t2) _parent.insertBefore(node1,_t2); else _parent.appendChild(node1); } function swap(){ var t1 = document.getElementById("t1").value; var t2 = document.getElementById("t2").value; swapNode(document.getElementById(t1),document.getElementById(t2)); } // --></script> <table> <tr> <td id="a">[a]</td> <td id="b">[b]</td> <td id="c">[c]</td> <td id="d">[d]</td> <td id="e">[e]</td> </tr> </table> <tr><td><input id="t1" type="text" value="a"></td></tr> <tr><td><input id="t2" type="text" value="b"></td></tr> <tr><td><input type="button" value="swap" onclick="swap()"></td></tr> </textarea><br><input onclick="runEx('runcode92002')" type="button" value="杩"> </div>