Javascript 为什么动态表的边框不显示

Javascript 为什么动态表的边框不显示,javascript,css,html,google-apps-script,Javascript,Css,Html,Google Apps Script,使用Google应用程序脚本创建web应用程序 我正在从电子表格中检索数据,并试图以表格格式显示 除了桌子的边框,一切都很好 下面是代码 <html> <body> <table border="1"> <script language="javascript" type="text/javascript"> window.onload = function() { google.script.run.wi

使用Google应用程序脚本创建web应用程序

我正在从电子表格中检索数据,并试图以表格格式显示

除了桌子的边框,一切都很好

下面是代码

 <html>

  <body>

<table border="1">
  <script language="javascript" type="text/javascript">

   window.onload = function()
   {
       google.script.run.withSuccessHandler(showData).getpres();
    }


 function showData(data)
 {
  var html = "";
  for (var i=0; i<data.length; i++) 
  { 
    if(data[i][0] <= 2)
    {


  document.write("<tr><td>Number " + i + " is:</td>");
  document.write("<td>" + data[i][3] + "</td></tr>");

    }
  }

}
    </script>
    </table>

   </body>
   </html>

window.onload=函数()
{
google.script.run.withSuccessHandler(showData.getpres();
}
函数showData(数据)
{
var html=“”;

对于(var i=0;i您的代码适合我,添加一个width属性,看看这是否有帮助,如果不只是使用css
border:1px solid#ccc;

来添加边框-更好地使用css内部样式标记,我为您添加了它

而且,据我所知,将脚本标记放在表中是不好的。 最好将脚本标记放在表标记旁边,最后一件事是您执行了document.write,这意味着浏览器必须在每次插入后更新页面布局,最好将所有行连接到一个字符串,并只添加一次

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <table id="table" class="table"></table>
        <script language="javascript" type="text/javascript">
            window.onload = function() {
                google.script.run.withSuccessHandler(showData).getpres();
            }
            function showData(data) {
                var rows = [];
                for (var i = 0, ii = data.length; i < ii; i++) {
                    if(data[i][0] <= 2) {
                        rows.push('<tr>');
                        rows.push('<td>Number ' + i + ' is:</td>')
                        rows.push('<td>' + data[i][3] + '</td>');
                        rows.push('</tr>');
                    }
                }
                document.getElementById('table').innerHTML = rows.join('');
            }
        </script>
        <style>
            .table{
                border: 1px solid black;
            }
        </style>
    </body>
</html>

文件
window.onload=函数(){
google.script.run.withSuccessHandler(showData.getpres();
}
函数showData(数据){
var行=[];
对于(变量i=0,ii=data.length;i如果(数据[i][0]来自:“HTML5不支持的边框属性。请改用CSS。”我也按照文档中的说明尝试了CSS,但它不起作用!!边框适用于其他一些代码..它不适用于此代码..要在每个单元格周围设置边框,请执行
td{border:1px纯黑;}
我已经为上面的代码添加了边框属性。现在,它工作得很好!!非常感谢