2014-05-24 28 views
0

我生成用於我的div動態IDS其示出了(+)加號按鈕的圖像如下所示兩個事件偵聽器如何並行工作?

<div id="'+random_number+'" class="inc buttontest">+</div><div class="dec buttontest">-</div> 

重要的是點擊,我與上述類使用登記。

$(document).on("click", ".buttontest", function() { 



}); 

點擊加號按鈕,我該如何乘以其他事件偵聽器中存在的值。

如果您看到圖像,請單擊加號按鈕,值75.00必須是75 * 2即150。

請瑟這裏

http://jsfiddle.net/u8Vft/2/

enter image description here

js的小提琴有誰請幫助我。我沒有任何想法如何去與此。

回答

2

在點擊plus/minus按鈕檢查爲inc/dec類,然後分別決定multiply/subtract喜歡:

$(document).on("click", ".buttontest", function() { 
    var $id = $(this).prevAll("input").first().attr("id"); 
    if($(this).hasClass("inc")){ 
     $(".cart").find("div").each(function(){ 
      if($(this).attr("id_attr")==$id){ 
     $(this).text(parseInt($(this).text(),10)+amountdd); 
      } 
     }); 
    }else if($(this).hasClass("dec")){ 
     $(".cart").find("div").each(function(){ 
      if($(this).attr("id_attr")==$id){ 
      $(this).text(parseInt($(this).text(),10)-amountdd); 
      } 
     }); 
    } 
    }); 

DEMO

+0

的加號按鈕的點擊,我會_1的存取到amountdd並相應地成倍增加,但我怎麼能更新到HTML.append('

'+amountdd+'
'); ?? – Pawan

+0

@PreethiJain:你可以在小提琴中分享你的乘法代碼嗎? – Unknown

+0

選擇一個複選框,然後點擊加號按鈕,然後你會得到一個提醒,請看這裏的提琴http://jsfiddle.net/u8Vft/5/ – Pawan