繁体   English   中英

将li附加到另一个html文件中的现有ul中

[英]append li into an existing ul inside another html file

我喜欢将li附加到现有的ul中,如下所示: jQuery:如何在现有的<ul>中添加<li>?

但是在我的代码中,li是来自另一个html文件的现有li。 因此,将ul具有products.html。 在这个html文件中,我想附加li

<li class="first-li" id="hotel_belle">
     <h2>Hotel Belle</h2>
     <div>
        <img class="sub-img" alt="picture from hotel" src="pic/products/HotelBelle.png" />
        <p>Lorem Ipsum</p>
        <a href="#"><img class="btn-cart" alt="add this product to cart" src="pic/book/cart.png" /></a>
     </div>    
 </li>

进入cart.html:

 <div id="inner-cart-content">
        <ul id="content-cart">
            <li>
               //The new li element from products.html

在JavaScript中,我这样写:

$(".btn-cart").click(function(){  
var cart = $(this).parents("li").eq(0);

//$("#inner-cart-content ul").append('cart'); <--this is not working
});

那我该怎么办?

$(".btn-cart").click(function(){
 var item = //grab what you want

 $("#content-cart ul").append(item);
 $("<div id="inner-cart-content">").show(); //After adding the item, show the cart
 $("div").delay(4000).hide(); And after 4 seconds hide it again!
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM