我有一张桌子,我正在尝试将表格中的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&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&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&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&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>
答案 0 :(得分:1)
你可以这样做。
$(".product_li").each(function()
{
$("#upsell").append($(this).html());
});
如果要在附加到追加销售后删除表中的div,可以执行$(this).remove();在循环中。
要获取元素本身,您可以克隆它。
$(".product_li").each(function()
{
$("#upsell").append($(this).clone());
});
答案 1 :(得分: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();