表格增加一行(转载)

<body>
<table id="tab">
<tr><td>0</td></tr>
<tr id="x"><td>1 在此行下插入新行</td></tr>
<tr><td>2</td></tr>
</table><br>
<input type="button" onclick="javascript:instTR()" value="插入行">
<script type="text/javascript">
function instTR(){
var tab=document.getElementById('tab');
var n=document.getElementById('x').rowIndex+1;
var tr=tab.insertRow(n);
var td=tr.insertCell(0);
td.innerHTML='new '+Math.random();
}
</script>
</body>







<html>
<head>
<script>
function changeLink()
{
document.getElementById('myAnchor').innerHTML="W3Cschool";
document.getElementById('myAnchor').href="http://www.w3cschool.cc";
document.getElementById('myAnchor').target="_blank";
}
</script>
</head>
<body>

<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<input type="button" onclick="changeLink()" value="Change link">

</body>
</html>
posted @ 2017-03-17 20:13  孜然风味  阅读(278)  评论(0编辑  收藏  举报