从ul中删除动态创建的包含多个源的li

时间:2017-08-04 19:34:42

标签: javascript c# jquery asp.net

import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tk8.6"

executables=[cx_Freeze.Executable("Game.py")]

cx_Freeze.setup(
    name="Game",
    options={"build_exe":{"packages":["pygame"],"include_files":["image1.png","image2.png"]}},
    description="Game",
    executables=executables
)

我想在有人点击添加到购物车时动态添加li。它转到带有id" ae__orders__content"的ul中的购物车。直到这一部分一切正常。但我想删除单击时从购物车中删除时动态添加的li。我已经尝试了几乎一切,并找到了下面给出的解决方案它会删除UL中的所有项目,而不是单击的唯一LI。

<div class="panel-body">
    <ul>
        <li class="clearfix"><span class="pull-left">One leg</span><a href="#" class="ae__add-cart pull-right"><img src="images/plus-icon.png" alt="" /><span>Add to Cart</span></a></li>
        <li class="clearfix"><span class="pull-left">Two Leg</span><a href="#" class="ae__add-cart pull-right"><img src="images/plus-icon.png" alt=""><span>Add to Cart</span></a></li>
        <li class="clearfix"><span class="pull-left">Full</span><a href="#" class="ae__add-cart pull-right"><img src="images/plus-icon.png" alt=""><span>Add to Cart</span></a></li>
        <li class="clearfix"><span class="pull-left">Half</span><a href="#" class="ae__add-cart pull-right"><img src="images/plus-icon.png" alt=""><span>Add to Cart</span></a></li>
    </ul>
</div>

<ul id="ae__orders__content">
</ul>



$(document).ready(function () {

    $(".clearfix").click(function () {
        var temp = $(this).text();
        var updatedString = temp.replace("Add to Cart", "");

        $("#ae__orders__content").append("<li id=\"" + updatedString + "\" class=\"clearfix\"><span class=\"pull-left\">");
        $("#ae__orders__content").append("<b>" + updatedString + "</b></span><a href=\"#\" class=\"ae__remove-cart pull-right\"><img src=\"images/sm-icon.png\" alt=\"\">Remove from Cart</a></li>");
    });
});

Add to cart is working fine. I want to remove li when remove from cart is clicked.

1 个答案:

答案 0 :(得分:0)

看起来您希望附加的<a>成为删除li的点击目标,所以:

$(".ae__orders__content").on("click", "a.ae__remove-cart", function () {
  $(this).parent().remove();
});