//点击插入
$('.Insert').each(function(){ $(this).click(function(){ var s = $(this).text(); var a = s.substring(0,s.length-1); //减掉右侧的加号 $(".SelectOkList").append("<div class='Subtract' onclick='Subtract(this)'>" + a + "<span class='num'>0</span><span>-</span></div>"); }) });
//点击删除
function Subtract(node){ $(node).remove(); }
//商品重复 + 1
<div class="Insert" data-id="Y1">心悦<span>+</span></div>
<div class="Insert" data-id="Y2">煊赫门<span>+</span></div>
<div class="Insert" data-id="Y3">利群<span>+</span></div>
<div class="Insert" data-id="Y4">南京<span>+</span></div>
<div class="Insert" data-id="Y5">雨花石<span>+</span></div>
<div class="Insert" data-id="Y6">荷花<span>+</span></div>
<div class="Insert" data-id="Y7">小熊猫<span>+</span></div>
<div class="Insert" data-id="Y8">金陵十二衩<span>+</span></div>
<div class="Insert" data-id="Y9">黄鹤楼<span>+</span></div>
<div class="Insert" data-id="Y10">云烟<span>+</span></div>
$(".Insert").click(function(){ var a = $(this).data("id"); var n = $(this).text(); var Tit = n.substring(0,n.length-1); if($(".right" + a).length != 0){ $(".right"+ a + " .num").text(parseInt($(".right"+ a + " .num").text()) + 1); }else{ $(".SelectOkList").append("<div class='Subtract right"+ a + "' onclick='Subtract(this)'>" + a + "<span class='num right"+ Tit + "'>0</span><span>-</span></div>"); } });