-2

我有一张桌子,我正在尝试获取表格中的 div(按类:product_li),我试图将它们放入另一个名为“upsell”的 div 元素中。我该怎么做呢?这是我的桌子的样子:

<table cellspacing="0" class="productTable"><tr><td id="catProdTd_6732684" class="productItem"><div class="product_li item-on-sale-0 aaronBell hide">
    <div class="grid_3">
        <img class="sale-0" src="/images/sale.png" />
        <div class="prev">
            <a href="/store/prints/gold-snake-and-skull"><img id="catsproduct_6732684" src="/images/Artists/Aaron-Bell/777.jpg" alt="Gold Snake and Skull" border="0" /></a>
        </div><!-- .prev -->
    </div><!-- .grid_3 -->

    <div class="grid_4">
        <div class="entry_content">
            <a href="/store/prints/gold-snake-and-skull"><h3 class="title">Gold Snake and Skull</h3></a>

            <p>Dimensions 12x15"<br />High Dynamic Range (HDR) Pigments<br />Printed on 100% Cotton Rag</p>

<span class="favorite-link">#6732684#<a class="favoritelink" href="/FavoriteProcess.aspx?OID=6732684&amp;OTYPE=27">[+] favorites</a></span> | <a class="more" href="/store/prints/gold-snake-and-skull">Learn More</a>

        </div><!-- .entry_content -->
    </div><!-- .grid_4 -->

    <div class="grid_2">
        <div class="cart">
            <div class="price">
                <div class="price_new">$39.95</div>
                <div class="price_old">$59.95</div>
            </div>
            <span class="btn-buy"><input class="productSubmitInput" name="AddToCart_Submit" type="submit" value="Buy Now" onclick="AddToCart(208719,6732684,'',3,'','',true);return false;" /></span>
        </div><!-- .cart -->
    </div><!-- .grid_2 -->

    <div class="clear"></div>
</div></td><td id="catProdTd_6732685" class="productItem"><div class="product_li item-on-sale-0 aaronBell hide">
    <div class="grid_3">
        <img class="sale-0" src="/images/sale.png" />
        <div class="prev">
            <a href="/store/prints/namakubi"><img id="catsproduct_6732685" src="/images/Artists/Aaron-Bell/500.jpg" alt="Namakubi" border="0" /></a>
        </div><!-- .prev -->
    </div><!-- .grid_3 -->

    <div class="grid_4">
        <div class="entry_content">
            <a href="/store/prints/namakubi"><h3 class="title">Namakubi</h3></a>

            <p>Dimensions 12x15"<br />High Dynamic Range (HDR) Pigments<br />Printed on 100% Cotton Rag</p>

<span class="favorite-link">#6732685#<a class="favoritelink" href="/FavoriteProcess.aspx?OID=6732685&amp;OTYPE=27">[+] favorites</a></span> | <a class="more" href="/store/prints/namakubi">Learn More</a>

        </div><!-- .entry_content -->
    </div><!-- .grid_4 -->

    <div class="grid_2">
        <div class="cart">
            <div class="price">
                <div class="price_new">$39.95</div>
                <div class="price_old">$59.95</div>
            </div>
            <span class="btn-buy"><input class="productSubmitInput" name="AddToCart_Submit" type="submit" value="Buy Now" onclick="AddToCart(208719,6732685,'',3,'','',true);return false;" /></span>
        </div><!-- .cart -->
    </div><!-- .grid_2 -->

    <div class="clear"></div>
</div></td><td id="catProdTd_6732686" class="productItem"><div class="product_li item-on-sale-0 adamHays hide">
    <div class="grid_3">
        <img class="sale-0" src="/images/sale.png" />
        <div class="prev">
            <a href="/store/prints/no-time-to-lose"><img id="catsproduct_6732686" src="/images/Artists/Adam Hays/1128.jpg" alt="No Time To Lose" border="0" /></a>
        </div><!-- .prev -->
    </div><!-- .grid_3 -->

    <div class="grid_4">
        <div class="entry_content">
            <a href="/store/prints/no-time-to-lose"><h3 class="title">No Time To Lose</h3></a>

            <p>Dimensions 12x16"<br />High Dynamic Range (HDR) Pigments<br />Printed on 100% Cotton Rag</p>

<span class="favorite-link">#6732686#<a class="favoritelink" href="/FavoriteProcess.aspx?OID=6732686&amp;OTYPE=27">[+] favorites</a></span> | <a class="more" href="/store/prints/no-time-to-lose">Learn More</a>

        </div><!-- .entry_content -->
    </div><!-- .grid_4 -->

    <div class="grid_2">
        <div class="cart">
            <div class="price">
                <div class="price_new">$39.95</div>
                <div class="price_old">$59.95</div>
            </div>
            <span class="btn-buy"><input class="productSubmitInput" name="AddToCart_Submit" type="submit" value="Buy Now" onclick="AddToCart(208719,6732686,'',3,'','',true);return false;" /></span>
        </div><!-- .cart -->
    </div><!-- .grid_2 -->

    <div class="clear"></div>
</div></td><td id="catProdTd_6732687" class="productItem"><div class="product_li item-on-sale-1 adamHays hide">
    <div class="grid_3">
        <img class="sale-1" src="/images/sale.png" />
        <div class="prev">
            <a href="/store/prints/reaper"><img id="catsproduct_6732687" src="/images/Artists/Adam Hays/1140.jpg" alt="Reaper" border="0" /></a>
        </div><!-- .prev -->
    </div><!-- .grid_3 -->

    <div class="grid_4">
        <div class="entry_content">
            <a href="/store/prints/reaper"><h3 class="title">Reaper</h3></a>

            <p>Dimensions 24x16"<br />High Dynamic Range (HDR) Pigments<br />Printed on 100% Cotton Rag</p>

<span class="favorite-link">#6732687#<a class="favoritelink" href="/FavoriteProcess.aspx?OID=6732687&amp;OTYPE=27">[+] favorites</a></span> | <a class="more" href="/store/prints/reaper">Learn More</a>

        </div><!-- .entry_content -->
    </div><!-- .grid_4 -->

    <div class="grid_2">
        <div class="cart">
            <div class="price">
                <div class="price_new">$39.95</div>
                <div class="price_old"><span style="text-decoration:line-through;">$69.95</span></div>
            </div>
            <span class="btn-buy"><input class="productSubmitInput" name="AddToCart_Submit" type="submit" value="Buy Now" onclick="AddToCart(208719,6732687,'',3,'','',true);return false;" /></span>
        </div><!-- .cart -->
    </div><!-- .grid_2 -->

    <div class="clear"></div>
</div></td></tr></table>
4

2 回答 2

1

你可以做这样的事情。

$(".product_li").each(function()
{
  $("#upsell").append($(this).html());
});

如果您想在追加销售后从表中删除 div,您可以执行 $(this).remove(); 在循环。

要获取元素本身,您可以克隆它。

$(".product_li").each(function()
{
  $("#upsell").append($(this).clone());
});
于 2013-10-30T21:11:38.143 回答
1

如果您需要添加容器 div,那么您可以使用以下内容:

$('body').append('<div id="#upsell"></div>');

注意:替换body为您需要产品进入的任何容器 div。

然后这将遍历 .product_li 的每个实例并将其附加到 id 为 #upsell 的 div:

$('.product_li').each(function() {
    $('#upsell').append($(this).html());
});

然后您可以运行以下命令来删除表:

$('.productTable').remove();
于 2013-10-30T21:18:22.530 回答