创建dynamically and add to

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建dynamically and add to相关的知识,希望对你有一定的参考价值。

我有一张桌子:

  <table id="fTable">
    <tbody>
        <tr id="fRow">

        </tr>
    </tbody>
  </table>

我有一个有30列的网格,如何做所有这些列来分隔<td>并想要设置<td> id,width,text或innerhtml属性。

              var row = $('#fRow');
              for(var i= 2; i < Columns.length ; i++)
               {

               }
答案

正如我想的那样(以及评论)......你是新手使用jquery ...所以使用jquery非常简单... append / appendTo就是你要找的......

如果你想为TD添加多个表,那么使用ID属性是没用的。因为W3C说ID在页面上是唯一的...更好地使用class属性...

<table class="floatTable">
    <tbody>
        <tr class="footerRow">

        </tr>
    </tbody>
  </table>

// Select all TRs in the floatTable having the class footerRaw
$('.floatTable tr.footerRaw').each(function(key, el)) {
  // here you could define anything whatever you want
  var tdContent = 'Lorem ipsum dolor';

  // For example add five TDs to your table
  for ( var i = 0; i < 5; i++ ) {
    // if it works ;-)
    // ...it should add following:
    // <td>Lorem ipsum dolor #1</td>
    // <td>Lorem ipsum dolor #2</td>
    // ...and so on...
    $(this).append('<td>' + tdContent + ' #' + i + '</td>');
  }
});

这是一个正在运行的例子...... http://jsfiddle.net/2am6wcm8/

以上是关于创建dynamically and add to的主要内容,如果未能解决你的问题,请参考以下文章

How to add user account on Linux(Automatically and Manually)

[leetcode]Dynamic Programming-121. Best Time to Buy and Sell Stock

How to clone a record and set its lookup field to new parent in Dynamics 365 CE

Android报错:WindowManager$BadTokenException: Unable to add window -- window has already been added(示例代

错误记录安卓 RecyclerView 报错 ( only use immediately and call holder.getAdapterPosition() to look it up )(代

报错Failed to configure a DataSource: 'url' attribute is not specified and no embedded datas(代