删除购物车中的选定项目

delete selected items in shoping cart

本文关键字:项目 购物车 删除      更新时间:2023-09-26

我做了一个类似购物车的东西,你可以把商品拖到选定的区域,它们就会出现在那里。我现在试图添加删除特定选定项目的选项,但我找不到合适的方法来这样做。有什么建议吗?

<section id="productCatalog">
    <div class="product">
        <h2 class="des">Product 1 </h2>
        <p class="description"> price: </p>
        <p class="price">400</p>
    </div>
    <div class="product">
        <h2 class="des">Product 2 </h2>
        <p class="description"> price: </p>
        <p class="price">200</p>
    </div>
<section id="shoppingCart">
    <h2 align="center">shopping cart</h2>
   </section>

脚本:

$(function(){
    $('.product').draggable({ 
        scroll: false, 
        containment: 'document' , 
        revert: true,
        start: function()
        {
            contents = $(this).text();
        }
     });
 $('#shoppingCart').droppable({ hoverClass: 'border', accept: '.product', drop: function()
      {
         $('#shoppingCart').append(contents + "<button id='butt' onclick='one()'>delete item</button>" + "<br>") 
      }}); 
      function one()
      {
      }
});

html

<section id="shoppingCart" class="ui-droppable">
    <h2 align="center">shopping cart</h2>
   <div>
        Product 1 
         price: 
        400
       </div>
    <button id="butt" onclick="one(this);">delete item</button><br></section>

js

function one(obj){
    var item = $(obj).prev().andSelf().remove();    
}

小提琴