簡體   English   中英

使用JavaScript繪制HTML表:找不到此網頁

[英]draw a HTML table using JavaScript: This web page has not been found

我有一個HTML:

<body>
<div id="list"></div>
<div>
  <script>
    var locations = ["Paya Lbar A","Paya Lebar B"];
    var HTML = '<table><tr style="background:#809FFF"><td align="center"><b><font color="royalblue" size=30>Location List</font></b></td></tr>';
    for(j=0;j<locations.length;j=j+1){
      var location = locations[j];
      HTML += "<tr><td align=center>"+location+"</td></tr>";
    }
    HTML += "</table>";
    document.getElementById("list").innerHTML = HTML;
  </script>
</div>
</body>

我只運行了這個文件,但出現錯誤:

No web page was found for the web address: file:///C:/Users/Li%20Dan/Desktop/Paya%20Lebar%20B

我完全不知道,有幫助嗎?

提前致謝!

您正在定義HTML Varible or location Variable ,這就是發生問題的原因。 HTML, locationreserve character所以我建議您change variable名稱以解決此問題,

檢查此演示jsFiddle

<div id="list"></div>
<div>
  <script>
    var locations = ["Paya Lbar A","Paya Lebar B"];
    var tbl = '<table><tr style="background:#809FFF"><td align="center"><b><font color="royalblue" size=30>Location List</font></b></td></tr>';
    for( j = 0 ; j < locations.length ; j++){
      tbl += "<tr><td align=center>" + locations[j] + "</td></tr>";
    }
    tbl += "</table>";
    console.log(tbl);
    document.getElementById("list").innerHTML = tbl;
  </script>
</div>

還有一件事情不聲明變量或將值賦給變量locations[j]以便於您輕松獲取此值,因此請使用這種方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM