【问题标题】:How to add header for dynamic table如何为动态表添加标题
【发布时间】:2012-06-16 10:46:30
【问题描述】:

大家好,我正在绘制动态表格,我想为表格添加标题如何将标题添加到动态表格这是我的表格代码:

$.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;       

});

任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • @Govind 感谢您编辑帖子
  • 你是在说&lt;th&gt; in table 还是别的什么
  • @CoDe 是的,我的意思是 。但是当我尝试使用它时,我得到了错误。
  • @PramodD 什么样的错误?并使用什么浏览器?卜,最重要的是,您实际尝试了什么?
  • 这里jsfiddle.net/75zFX/6 我试过但是如果我删除了那么表是可见的

标签: javascript jquery html jquery-ui


【解决方案1】:

你可以建立你的标题:

var header = "<th>...</th>";

然后:

$("table").append(header);

【讨论】:

    【解决方案2】:

    如果我能正确理解你的观点

    演示http://jsfiddle.net/75zFX/8/

    var colheader = '<tr><th>Column1</th><th>Column2</th> .....</tr>\n';
    var tbody = colheader ;// and replace with var tbody = '';
    

    【讨论】:

      【解决方案3】:

      如果您想手动将表头添加到表中,请使用此代码。

      JSP

      <th id="example"></th>
      

      JavaScript

      $("#example").html("Header Value"); 
      

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签