首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JS增加表格行出有关问题了。

2012-12-30 
JS增加表格行出问题了。。。我用JS增加表格行,怎么加不上去呢?一加上马上就消失了。。。!DOCTYPE htmlhtmlh

JS增加表格行出问题了。。。
我用JS增加表格行,怎么加不上去呢?一加上马上就消失了。。。

<!DOCTYPE html>
<html>
  <head>
    <title>test.html</title>
<script type="text/javascript">
function addRow() {
var tbl = document.getElementById("tbl");

var newRow = tbl.insertRow(1);

var newCell1 = newRow.insertCell();

newCell1.innerHTML = "newCell";
alert(1);
}
</script>
  </head>
  
  <body>
    <table id="tbl" border="1">
    <tbody id="tbl">
    <tr>
    <td>123</td>
    <td>456</td>
    </tr>
    </tbody>
    </table>
    <a href="" onclick="addRow()">add</a>
  </body>
</html>

[解决办法]
<!DOCTYPE html>
<html>
  <head>
    <title>test.html</title>
<script type="text/javascript">
function addRow() {
var tbl = document.getElementById("tbl");

var newRow = tbl.insertRow(1);

var newCell1 = newRow.insertCell();

newCell1.innerHTML = "newCell";
alert(1);
}
</script>
  </head>
  
  <body>
    <table id="tbl" border="1">
    <tbody id="tbl">
    <tr>
     <td>123</td>
     <td>456</td>
    </tr>
    </tbody>
    </table>
    <a href="javascript:void(0)" onclick="addRow()">add</a>
  </body>
</html>
a标签href添加红色部分  你页面跳转了

热点排行