代碼
複製代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<title>無標題頁</title>
</head>
<body>
<table id="tb1" border="1" cellpadding="3">
<tr>
<th>移動</th>
<th>資料</th>
<th>資料</th>
<th>資料</th>
</tr>
<tr>
<td>*</td>
<td>11111111111</td>
<td>sdgergserhserhserh</td>
<td>awegaw</td>
</tr>
<tr>
<td>*</td>
<td>222222222</td>
<td>serherwwwwww</td>
<td>fafafff</td>
</tr>
<tr>
<td>*</td>
<td>333333333</td>
<td>qqqqqqqwewer</td>
<td>yukyuk</td>
</tr>
</table>
<script type="text/javascript">
var curTr = null;
var tb1 = document.getElementById('tb1');
var trs = tb1.getElementsByTagName('tr');
tb1.onselectstart = function(){
if(curTr){
document.selection.empty(); return true;
}
};
for(var i=1; i<trs.length; i++) {
var tds = trs[i].getElementsByTagName('td');
tds[0].style.cursor = 'move';
tds[0].onmousedown = function(){
curTr = this.parentNode;
curTr.style.backgroundColor = '#eff';
};
tds[0].onmouseover = function() {
if(curTr && curTr != this.parentNode) {
this.parentNode.swapNode(curTr);
}
}
}
document.body.onmouseup = function(){
if(curTr){
curTr.style.backgroundColor = '';
curTr = null;
}
};
</script>
</body>
</html>
註:不相容firefox,在IE和chrome下測試通過哦。