本帖最后由 zhangweitc123 于 2014-12-26 16:44:19 编辑

解决方案 »

  1.   

    没人回答,自己顶一下,时appendChild的问题
      

  2.   

    这是编辑过后的html内容
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript">
       window.onload = function(){
        var tb = document.getElementById("tb");
        
      tb.appendChild("<tr><td>00010001</td><td>子目录-01</td><td>45.0</td><td>45.0</td></tr>");

      tb.appendChild("<tr><td>00010002</td><td>子目录01-1</td><td>60.0</td><td>60.0</td></tr>");

       }
    </script>
    </head>
      
    <body>
    <div align="center">
      <p>电费统计报表</p>
      <table width="400" border="0" id="tb">
        <tr>
          <th width="150">编码</th>
          <th width="150">电表名称</th>
          <th width="150">用电量</th>
          <th width="150">金额</th>
        </tr>
      </table>
    </div>
    </body>
      
    </html>
      

  3.   


    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import ="java.util.*,com.ruixin.entity.*"%>
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <script type="text/javascript">
           window.onload = function(){
            var tb = document.getElementById("tb");
            <%
                List reportList=(List)request.getAttribute("reportList");
                for(int i=0;i<reportList.size();i++){
                    Report report=(Report)reportList.get(i);
                    %>
           var tr=document.createElement('tr');
            var td1=document.createElement('td');
            var td2=document.createElement('td');
            var td3=document.createElement('td');
            var td4=document.createElement('td');
            td1.innerText=<%=report.getCode()%>;
            td2.innerText=<%=report.getName()%>;
            td3.innerText=<%=report.getUseNum()%>;
            td4.innerText=<%=report.getMoney()%>;
           tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);
            tb.appendChild(tr);
                        //////// tb.appendChild("<tr><td><%=report.getCode()%></td><td><%=report.getName()%></td><td><%=report.getUseNum()%></td><td><%=report.getMoney()%></td></tr>"); 
                    <%
                }
                %>
           }
        </script>
    </head>
       
    <body>
    <div align="center">
      <p>电费统计报表</p>
      <table width="400" border="0" id="tb">
        <tr>
          <th width="150">编码</th>
          <th width="150">电表名称</th>
          <th width="150">用电量</th>
          <th width="150">金额</th>
        </tr>
      </table>
    </div>
    </body>
       
    </html>
      

  4.   


        <script type="text/javascript">
          window.onload=function(){
            var tb=document.getElementById('tb');
            tb.appendChild("<tr><td>a</td><td>b</td><td>c</td><td>d</td></tr>"); 
            //你可以试一下这种最简单的在table中动态添加td的方式,但是这明显是不行的,appendChild()中添加的应该是动态
           //创建好的标签,而js中创建标签使用的是标签名称,例如:document.createElement('div'),并不是将div改为<div></div>
           //document.createElement('<div></div>');有点类似于jquery中的$div=$("<div id='div1'></div>");,但是js并不支持这种
          //动态创建标签的方式
          }
        </script>
      

  5.   


        <script type="text/javascript">
          window.onload=function(){
            var tb=document.getElementById('tb');
            tb.appendChild("<tr><td>a</td><td>b</td><td>c</td><td>d</td></tr>"); 
            //你可以试一下这种最简单的在table中动态添加td的方式,但是这明显是不行的,appendChild()中添加的应该是动态
           //创建好的标签,而js中创建标签使用的是标签名称,例如:document.createElement('div'),并不是将div改为<div></div>
           //document.createElement('<div></div>');有点类似于jquery中的$div=$("<div id='div1'></div>");,但是js并不支持这种
          //动态创建标签的方式
          }
        </script>
    嗯,知道了,谢谢解答