日期:2014-05-16 浏览次数:20408 次
<table>
<tr>
<td>1.2</td>
<td></td>
</tr>
<tr>
<td>4.5</td>
<td></td>
</tr>
<tr>
<td>3.44</td>
<td></td>
</tr>
</table>
<table>
<tr>
<td>1.2</td>
<td>3</td>
</tr>
<tr>
<td>4.5</td>
<td>1</td>
</tr>
<tr>
<td>3.44</td>
<td>2</td>
</tr>
</table>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 ">
<title> 新建网页 2 </title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function() {
var table = document.getElementById("test");
var arr = [];
for(var i =0;i < table.rows.length;i++) {
arr.push(table.rows[i].cells[0].firstChild.nodeValue);
}
arr.sort(function(a,b){ return parseFloat(a) - parseFloat(b);})
for(var i =0; i < table.rows.length;i++) {
for(var j = 0; j < arr.length; j++) {
if(table.rows[i].cells[0].firstChild.nodeValue == arr[j].toString()) {
table.rows[i].cells[1].innerHTML = j+1;
break;
}
}
}
};
</script>
</head>
<body>
<table id="test">
<tr>
<td>1.2</td>
<td></td>
</tr>
<tr>
<td>4.5</td>
<td></td>
</tr>
<tr>
<td>3.44</td>
<td></td>
</tr>
</table>
</body>
</html>