如何在表格单元格中添加图像

How to add image in table cell

本文关键字:添加 图像 单元格 表格      更新时间:2023-09-26

嗨,我想根据表格中的条件在表格单元格中添加图像。我正在使用动态表,如下所示:

$.get('http://myDomain.com/RIA/topIndiaDetails.asp', function(data)
{    
    console.log("####"+data);
    var up = new Image();
    var down = new Image();
    up.src = "../../jquery.mobile/images/up.png";
    down.src = "../../jquery.mobile/images/down.png"
    substr = data.split('$');
    //alert(substr.length);
    //var theader = '<table border="1">'n';
    //<table id="auditOverview" border="1">
    var theader = '<table border="1" id='"tableId'">'n';
    var tbody = '';
    for (var out = 1;out<substr.length-1;out++)
    {
        //alert(substr[out]);
        tbody += '<tr>';
        var pra = substr[out].split('|^');
        //alert('pra.length is: '+pra.length);
        for (var i=0;i<pra.length-1;i++)
        {
            tbody += '<td>';
            if (pra[i]=="Red")
            {
                pra[i].append("<img id='theImg' src='../../jquery.mobile/images/down.png'/>");
            }
            else if (pra[i]=="Green")
            {
                pra[i].append("<img id='theImg' src='../../jquery.mobile/images/up.png'/>");
            }
            tbody += pra[i];    
            tbody += '</td>'  
        }
        tbody += '</tr>'n';
    }       
    var tfooter = '</table>';
    document.getElementById('wrapper').innerHTML = theader + tbody + tfooter;       
});

现在我正在检查条件是否if (pra[i]=="Green")然后我想在单元格中添加图像而不是"绿色"字符串,红色字符串也是如此。 任何帮助将不胜感激。提前谢谢。

而不是 :

pra[i].append("<img id='theImg' src='../../jquery.mobile/images/up.png'/>");

pra[i] = "<img id='theImg' src='../../jquery.mobile/images/up.png'/>";