1

操作するテーブルがありますが、ここでサンプルを提供します..テーブルには th と td が含まれています。th のタイトルを使用して列を見つけると仮定し、その列を必要な場所に移動する必要があります。

私の場合、私は作品を作り、夕方以降に朝のコラムに追加しようとしましたが、間違った結果が得られました。

HTML:

<table>
    <tbody>
        <tr>
            <th>Morning</th>
            <th>Afternoon</th>
            <th>Evening</th>
        </tr>
<tbody>
<tbody>
        <tr>
            <td>go to School</td>
            <td>go to Lunch</td>
            <td>go to Sleep</td>
        </tr>
    </tbody>
</table>

jQuery コード:

var morningIndex = $('tr th:contains(Morning)').index();
var Evening = $('tr th:contains(Evening)');


$.each($('tr'), function(n,v){
    morningCol = $(v).children().get(morningIndex);
    $(Evening).after(morningCol);
})

jsfiddle

4

1 に答える 1

1

これは私のために働いています:

var morningIndex = $('tr th:contains(Morning)').index();
var Evening =  $('tr th:contains(Evening)').index();

        $.each($("table tr"), function() { 
            $(this).children(":eq("+Evening+")").after($(this).children(":eq("+morningIndex+")"));
        });

皆さんありがとう。

于 2013-01-17T09:48:13.057 に答える