0

以下は私のhtmlです

<table id="myTable" class="dropdown">
 <thead> ........... </thead>
 <tbody class="myTbody1">
            <!--     insert here       -->
 <tbody class="myTbody2">
 <tbody class="myTbody3">
</table>

以下のhtml文字列をtbodyの直後に挿入する必要があります。myTbody1

var html = '<tbody class="details" colspan="9">
<table>
    <thead> 
        <tr>
            <th> Col1 </th>     
            <th> Col2 </th>     
            <th> Col3 </th>     
            <th> Col4 </th>     
            <th> Col5 </th>     
            <th> Col6 </th>     
            <th> Col7 </th>     
            <th> Col8 </th>     
            <th> Col9 </th> 
        </tr>
    </thead>    
    <tbody class="head">    
        <tr class="nestedRow">              
            <td> Data</td>      
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
        </tr>
    </tbody>
</table>
</tbody>'

私は以下のようにしようとしました、そしてそれは正しい場所に挿入します、しかしそれはhtml文字列から最初の2つのタグtbodyとtableを切り取っています。

$(html).insertAfter($(this));

ここで$(this)等しいtbody.myTbody1

どんな助けでも大歓迎です。

4

2 に答える 2

2

指定されているように、要素tbodyのみを含めることができます。tr渡すHTMLは無効であるため、jQueryはDOMで作成された有効な部分でのみ機能します。

このようなネストされたテーブルを作成するには、の子としてtrtd要素を追加しtbody、内部テーブルをの中に配置する必要がありtdます。

于 2012-11-19T17:53:36.900 に答える
0

Shahilが提供するJQueryを使用してテーブルを簡単にネストできますが、ネストされたテーブル全体を「tr」の開始タグと終了タグで囲む必要があります。2番目のコード例は次のようになります

var htmlToInsert = '<tr>
<td class="details" colspan="9">
<table>
    <thead> 
        <tr>
            <th> Col1 </th>     
            <th> Col2 </th>     
            <th> Col3 </th>     
            <th> Col4 </th>     
            <th> Col5 </th>     
            <th> Col6 </th>     
            <th> Col7 </th>     
            <th> Col8 </th>     
            <th> Col9 </th> 
        </tr>
    </thead>    
    <tbody class="head">    
        <tr class="nestedRow">              
            <td> Data</td>      
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
            <td> Data</td>
        </tr>
    </tbody>
</table>
<td>
</tr>'

次に、JQueryを使用します$('.myTBody1').html(htmlToInsert);

最後に、<tbody>タグに一致する</tbody>終了タグがあることを確認してください。

詳細については、JQuery APIにアクセスしてください-.html()

于 2012-11-19T18:21:16.687 に答える