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

解决方案 »

  1.   


    刚刚不小心按到了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 is a comment start -->
    <script type="text/javascript">
        <!--
        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>
    专家们能知道一下吗?为什么我的按钮点击时无效呢
      

  2.   

    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>
      

  3.   


    刚刚不小心按到了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 is a comment start -->
    <script type="text/javascript">
        <!--
        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>
    专家们能知道一下吗?为什么我的按钮点击时无效呢
    JS代码没有写在function里。LZ的写法是页面加载时执行。要使点击生效,应该写functionfunction setTd() {
        document.getElementById('table1').rows(1).cells(1).innerHTML="2013-08-08";
    }
      

  4.   

    <!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 is a comment start -->
    <script type="text/javascript">
        <!--
    var setTd = function(){
    document.getElementById('table1').rows[1].cells[0].innerHTML="2013-08-08";
    }
        //-->
    </script>
     
    <!-- This is a comment end -->
    <input type="button" value="读取" onclick="setTd()">
     
     
    </body>
    </html>参考下
      

  5.   


    大侠,你执行后是可以的吗,能介个图给我看看啊,我这里怎么测试不行啊,而且现在还是乱码,我这个是在IE里执行的哦因為我加了<meta http-equiv="content-type" content="text/html; charset=utf-8">
    去掉就可以了。,不過樓上已經給出方案,用row[1]代替row(0)可以兼容不同瀏覽器了。