0

これを手伝ってくれませんか。

私はこのようなテーブルを持っています:

     <table>
     <th style="text-align: left; text-transform: capitalize;">Unique</th>
     <th style="text-align: left; text-transform: capitalize;">x1</th>
     <th style="text-align: left; text-transform: capitalize;">y2</th>
     <tr class="rowNormal">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     <tr class="rowAlternate">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     <tr class="rowNormal">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     </table>

私がする必要があるのは、それぞれの後に特定のHTMLを挿入し、そのtr最後の値を使用してそのHTML内の変数を設定することです。つまり、上記のコードは次のようになります。tdtr

     <table>
     <th style="text-align: left; text-transform: capitalize;">Unique</th>
     <th style="text-align: left; text-transform: capitalize;">x1</th>
     <th style="text-align: left; text-transform: capitalize;">y2</th>
     <tr class="rowNormal">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     <p>
     <ac:macro ac:name="mymacro">
     <ac:parameter ac:name="content">titles</ac:parameter>
     <ac:parameter ac:name="labels">+VALUE_TD +othervalue</ac:parameter>
     </ac:macro>
     </p>
     <tr class="rowAlternate">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     <p>
     <ac:macro ac:name="mymacro">
     <ac:parameter ac:name="content">titles</ac:parameter>
     <ac:parameter ac:name="labels">+VALUE_TD +othervalue</ac:parameter>
     </ac:macro>
     </p>
     <tr class="rowNormal">
     <td nowrap="true">a1</td>
     <td nowrap="true">b2</td>
     <td nowrap="true">b3</td>
     </tr>
     <p>
     <ac:macro ac:name="mymacro">
     <ac:parameter ac:name="content">titles</ac:parameter>
     <ac:parameter ac:name="labels">+VALUE_TD +othervalue</ac:parameter>
     </ac:macro>
     </p>
     </table>

この例では、 VALUE_TD3行すべてでb3に等しくなります。

4

2 に答える 2

2

jQuery 関数を使用した例を次に示しますinsertAfter

jsFiddle を参照してください

$(document).ready(function () {
    $.each($('tr'), function (i, row) {
        if (i != 0) {
            var lastTd = $(row).find('td:last-child')[0];
            $('<p>\
<ac:macro ac:name="mymacro">\
<ac:parameter ac:name="content">titles</ac:parameter>\
<ac:parameter ac:name="labels">' + lastTd.innerHTML + 'othervalue</ac:parameter>\
</ac:macro>\
</p>').insertAfter(row);
        }
    });
});

jQuery関数を使用した別の例を次に示しますafter。どちらも機能しますが、それは単に異なる方法です。

jsFiddle を参照してください

$(document).ready(function () {
    $.each($('tr'), function (i, row) {
        if (i != 0) {
            var lastTd = $(row).find('td:last-child')[0];
            $(row).after('<p>\
<ac:macro ac:name="mymacro">\
<ac:parameter ac:name="content">titles</ac:parameter>\
<ac:parameter ac:name="labels">' + lastTd.innerHTML + 'othervalue</ac:parameter>\
</ac:macro>\
</p>');
        }
    });
});

また、いくつかの理由から、これは有効な HTML ではないと言いたいです。

  • <th>でラップする必要があり<tr>ます。
  • タグは<p>タグ内では無効です<table>
于 2013-03-05T08:39:42.180 に答える
0

trいいねの たびに 1 つの div を作成する<div id="tr1"> </div>

jqueryを使用すると、htmlスクリプトを追加できます

$('#tr1').append('your script');
于 2013-03-05T08:39:12.877 に答える