javascript - 生成只有一列的表

标签 javascript html

您好,我尝试生成一个只有一列的表格。所以我的链接只显示在一栏中。

这是我的功能:

    function createTableForPdfFiles() {

        //To Create The Table
        var table = document.createElement("table");
        table.setAttribute('id', 'pdfTable');
        table.setAttribute('class', 'AANTable');

        // insert Title Row
        var TitleRow = table.insertRow();
        var cell = TitleRow.insertCell(); 
        cell.setAttribute('class', 'AANTitleRow');
        cell.setAttribute('colSpan', pdfFiles.length + 1);
        cell.appendChild(document.createTextNode("Datenblätter"));

        //Insert Table Rows
        var pdfRow = table.insertRow();
        var cell = pdfRow.insertCell(); //Where the PDF´s are displayed
        cell.setAttribute('class', 'AANPdfRow');

        for (var i = 0; i < pdfFiles.length; i++) {
            var cell = pdfRow.insertCell();
            var link = document.createElement("a");
            link.setAttribute("href", "www.test.at" + pdfFiles[i].Link);
            var linktext = document.createTextNode(pdfFiles[i].Link);
            link.appendChild(linktext);
            cell.appendChild(link);
            cell.setAttribute('class', 'AANPdfCell');

        }

        $("#divTable").append(table);
}

现在看起来像: Wrong Table

但我希望它看起来像: good Table

那么我怎样才能做到这一点呢?我试图向表中添加另一行,但调试器说不支持......任何帮助都会非常好。

谢谢你的时间。

最佳答案

您必须为每个 pdf 创建一个新行。

要放这个

var pdfRow = table.insertRow();
var cell = pdfRow.insertCell(); //Where the PDF´s are displayed
cell.setAttribute('class', 'AANPdfRow');

在for里面

看看这个 -> fiddle

关于javascript - 生成只有一列的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36743848/

相关文章:

javascript - 如何在 Jquery 多选中选择一个包含其 parent 和 child 的组

javascript - 动态更改输入元素值

javascript - 包含来自其他网站的 html 文件吗?

javascript - 如何获取字符串的一部分?

javascript - Qt Webkit : Not allowed to load local resource

javascript - react : 'this.state' of parent component is undefined inside a child component function

html - 无法在浏览器中查看我的 .ASP 页面

html - AngularJS 风格不适用于新环境

javascript - 到达水平滚动端时如何设置[禁用] attr? (小 slider )

html - 按钮元素中的顶部对齐文本?