为动态html表中的属性分配变量值

时间:2018-08-21 12:43:13

标签: html

我有一个非常简单的问题。我在这里变得有点疯狂。我正在动态创建html表。我想在<input>内为<td>标记设置属性值。 例如: 以下是我的<td>

<td class="sorting_1"><input dummy="111"></td>

现在,我想使用变量设置虚拟属性值。即我将虚拟属性值存储在如下所示的变量中:

var dummyVar=111;

我想在<td>中分配/使用上述变量,如下所示:

<td class="sorting_1"><input dummy=dummyVar></td>

我该怎么做?

我正在以动态方式创建动态表:

var issueTableId = "issuetable_"+formattedCKEY;
    var $issuetable = $("
    <table  id='" + issueTableId + "' class='stripe nowrap'  style='position:relative; top:0px; width:95%;'></table>
    ");
    $issuetable.append('
    <thead>
       ').children('thead')
       .append('
       <tr />
          ').children('tr')
          .append('
          <th nowrap>Select</th>
          '+
          '
          <th nowrap>Priority</th>
          ' +
          '
          <th nowrap>Issue ID</th>
          ' +
          var $tbody = $issuetable.append('
    <tbody />
       ').children('tbody');
       $.each(cases, function () {
       $tbody.append('
       <tr />
          ').children('tr:last')
          .append('
          <td nowrap><input type="checkbox" />&nbsp;</td>
          ')
          .append('
          <td nowrap>' + $(this).find("PRTY").text() + '</td>
          ')
          .append(sourceRow)
          .append('
          <td nowrap>' + $(this).find("ISSUEID").text() + '</td>
          ');
          });

1 个答案:

答案 0 :(得分:0)

我明白了,我可以做这样的事情:

'<td nowrap><input type="checkbox" align="center" style="cursor: hand" name="selectIssue" dummy='+dummyVar+'>&nbsp;</td>'