日期:2014-05-19 浏览次数:20790 次
<html> <head> <title>这种方式支持任何浏览器</title> <script> function swapTR(action){ var oSelIpt = null; var iptArr = document.getElementsByTagName('input'); for(var i=0,len=iptArr.length;i<len;i++){ if(iptArr[i].checked){ oSelIpt = iptArr[i]; break; } } if(!oSelIpt) return; var _row = oSelIpt.parentNode.parentNode; if(action==0) //上移 { if(_row.previousSibling)//如果不是第一行 swapNode(_row, _row.previousSibling); }else{ if(_row.nextSibling) swapNode(_row, _row.nextSibling); } //保证换行后单选框选中ie中 oSelIpt.checked = true } function swapNode(node1, node2){ var _parent = node1.parentNode; //获取两个结点的相对位置 var _t1 = node1.nextSibling; var _t2 = node2.nextSibling; //将node2插入到原来node1的位置 if(_t1) _parent.insertBefore(node2, _t1); else _parent.appendChild(node2); //将node1插入到原来node2的位置 if(_t2)_parent.insertBefore(node1,_t2); else _parent.appendChild(node1); } function cleanWhitespace(element) { for(var row = element.rows[0]; row; row = row.nextSibling){ if(row.nodeType==3){ var _row; if(!row.previousSibling) _row = row.nextSibling; else _row = row.previousSibling; row.parentNode.removeChild(row); row = _row; } } } window.onload = function(){ cleanWhitespace(document.getElementById('tab_test')); //火狐的tr间会有textnode节点,把他们都移除掉 } </script> </head> <body> <table id="tab_test"> <tr> <td><input type='radio' name='row' checked /></td><td>1 </td><td>1 </td><td>1 </td> </tr> <tr> <td><input type='radio' name='row' /></td><td>2 </td><td>2 </td><td>2 </td> </tr> <tr> <td><input type='radio' name='r