日期:2014-05-16  浏览次数:20309 次

javascript怎么实现动态填充html里table里的内容呢?
刚刚被领导逼着弄公司里的嵌入式WEB维护,现在在自学javascript,

------解决方案--------------------
1.你的程序只能在IE运行
2.按钮点击无效,是因为onclick="setTd()" setTd这个方法没有

修改如下:使用IE,点击读取,rtu这个位置会更新为2013-08-08

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>this is a test web</title>
</head>
<body>

<h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
    <tr>
        <th>时间</th>
        <th>设备</th>
        <th>事项</th>
    </tr>
    <tr>
        <td>2013-09-09</td>
        <td>rtu</td>
        <td>reboot</td>
    </tr>

</table>


<!-- This is a comment start -->
<script type="text/javascript">
    <!--
function setTd(){
document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
}
    //-->
</script>

<!-- This is a comment end -->
<input type="button" value="读取" onclick="setTd()">


</body>
</html>

------解决方案--------------------
引用:
Quote: 引用:

刚刚被领导逼着弄公司里的嵌入式WEB维护,现在在自学javascript,


刚刚不小心按到了ENTER键,问题没说完就发布了,现在我的代码如下
<!DOCTYPE html>
<html>
<head>
    <title>this is a test web</title>
</head>
<body>

<h4 align="center">事件记录</h4>
<table id="table1" width="600" border="1px" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse" align="center">
    <tr>
        <th>时间</th>
        <th>设备</th>
        <th>事项</th>
    </tr>
    <tr>
        <td>2013-09-09</td>
        <td>rtu</td>
        <td>reboot</td>
    </tr>

</table>


<!-- This