Chrome中没有内容的表格

时间:2013-12-05 17:49:38

标签: jquery dom

我正在尝试在Chrome中显示包含其内容的表格。但是,我只能在Firefox和Opera(我到目前为止测试过的浏览器)中这样做。有趣的是,为所有提到的浏览器设置了td元素的textContent:

<table id="total" style="width:300px;margin-top:20px;">
 <tr>
   <td></td> 
   <td></td> 
 </tr>
 <tr>
   <td></td> 
   <td></td> 
 </tr>
 <tr>
   <td></td> 
   <td></td> 
 </tr>
</table> 

configText: function(elem, msg)
{
    "use strict";
    if (typeof elem === "undefined")
    {
        throw new Error("elem does not exist");
    }
    else if (elem.nodeType !== 1)
    {
        throw new Error("elem is not a valid element");
    }
    else if (typeof msg !== "string")
    {
        throw new Error("msg is not a string");
    }
    else {
        if ("textContent" in elem)
        {
            delete elem.textContent;
            elem.textContent = msg;
        }
        else if ("innerText" in elem)
        {
            delete elem.textContent;
            elem.innerText = msg;
        }
    }
 }


function createTotalTable(arrayTotal, arrayMsg)
{
"use strict";

var td;
var arrayCounter = 0;
var table = document.createElement("table");
for (var i = 0; i < 3; i++)
{
    var tr = document.createElement("tr");
    for (var j = 0; j < 2; j++)
    {
        td = document.createElement("td");
        if (j % 2 === 0)
        {
            U.configText(td, arrayMsg[arrayCounter]);
            arrayCounter++;
        }
        tr.appendChild(td);
    }
    try {
        U.configText(td, arrayTotal[i]);
    }
    catch (err)
    {
        console.log("Error: " + err.name + " on file " +
                err.fileName + " at line number " + err.lineNumber + " with message " + err.message);
    }

    table.id = "total";
    table.appendChild(tr);
    table.style.width = "300px";
    table.style.marginTop = "20px";
}

// elem.parentNode.insertBefore(table, elem.nextSibling);
$(table).insertAfter($("#graphics"));
}

0 个答案:

没有答案