JavaScript 自动在表格前面增加序号

<script language="javascript" type="text/javascript">
	    window.onload = function(){
		    var oTable = document.getElementById("num");
		    for(var i=0;i<oTable.rows.length;i++){
		    oTable.rows[i].cells[0].innerHTML = (i+1);
	    }
    }
    </script>

注意:要在table中添加id才能生效:<tbody id="num">

相关推荐