无法获取在 JS 中创建的表(或正文中的任何内容)以显示在浏览器中

Can't get table (or anything in body) created in JS to display in browser

本文关键字:任何内 浏览器 显示 正文 获取 JS 创建      更新时间:2023-09-26

我已经对此进行了几个小时的故障排除,找不到我知道的任何语法错误。我无法让表显示 AT。都。我截断了声明 HTML 类型的代码开头以及家庭作业中包含的注释。我只有几周的JS经验,在网站上发现了类似的问题,但找不到适用于我的问题。请帮助我弄清楚为什么除了徽标和地址之外,我无法显示任何其他内容!我对HTML不是很流利。(明天到期)

<script type="text/javascript" src="list.js"></script>
   <script type="text/javascript">
      var total = 0;
      function amountTotal(){
         var total = 0;
         for (var i = 0; i <= amount.length; i++){
            total = total + amount[i];
         }
         return total;
      }
   </script>
   <title>The Lighthouse</title>
   <link href="lhouse.css" rel="stylesheet" type="text/css" />
</head>
<body>
   <div id="title">
      <img src="logo.jpg" alt="The Lighthouse" />
      The Lighthouse<br />
      543 Oak Street<br />
      Owensboro, KY &nbsp;&nbsp;42302<br/>
      (270) 555-7511
   </div>
   <div id="data_list">
      <script type="text/javascript">
         document.write("<table border='1' rules='rows' cellspacing='0'>");
         document.write("<tr>");
         document.write("<th>Date</th><th>Amount</th><th>First Name</th><th>Last Name</th><th>Address</th>");
         document.write("</tr>");
            for (var i = 0; i < amount.length; i++) {
               If (i % == 0) {
                  document.write("<tr>");
               } else {
                  document.write("<tr class='yellowrow'>");
               }
               document.write("<td>"+ date[i] +"</td>");
               document.write("<td class='amt'>"+ amount[i] +"</td>");
               document.write("<td>"+ firstName[i] +"</td>");
               document.write("<td>"+ lastName[i] +"</td>");
               document.write("<td>"+ street[i] +"</ br>");
               document.write(city[i] + ", " + state[i] + " " + zip[i]);
               document.write("</td>");
               document.write("</tr>");
               document.write("</table>");
            }
      </script>
   </div>
   <div id="totals">
      <script type="text/javascript">
         document.write("<table border='1' cellspacing='1'>");
         document.write("<tr>");
         document.write("<th id='sumTitle' colspan='2'>Summary</th>");
         document.write("</tr>");
         document.write("<tr>");
         document.write("<th>Contributors</th>");
         document.write("<td>"+ amount.length +"</th>");
         document.write("</tr>");
         document.write("<tr>");
         document.write("<th>Amount</th>");
         document.write("<td>"+ amountTotal() +"</td>");
         document.write("</tr>");
         document.write("</table>");
   </div>
</body>
</html>

你注意到这段代码了吗?

If (i % == 0) {
   document.write("<tr>");
} 

在第二个脚本块中。我认为应该是

if(i%something == 0)
{
    document.write("<tr>");
}
相关文章: