2011-04-26 6 views
0
내가 jQuery를 계산기 플러그인을 사용하고

(http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm) 운동과 비용을 계산할 때 작은 문제를 우연히 발견하지 컵 케이크의.의 jQuery 계산

나는 1-12 제품 £ 19, 13-24 제품 £ 37, 또는 25 개 제품에 대한 £ 1.45를 필요로하지만,이 보여 합계를 변경하는 방법을 작동하지 않을 수 있습니다.

아무도 도와 줄 수 있습니까? 지금까지

내 코드 ...

var bIsFirebugReady = (!!window.console && !!window.console.log); 

$(document).ready(
    function(){ 
     // update the plug-in version 
     $("#idPluginVersion").text($.Calculation.version);); 


     // bind the recalc function to the quantity fields 
     $("input[name^=qty_item_]").bind("keyup", recalc); 
     // run the calculation function now 
     recalc(); 

     // automatically update the "#totalSum" field every time 
     // the values are changes via the keyup event 
     $("input[name^=sum]").sum("keyup", "#totalSum"); 

     // automatically update the "#totalAvg" field every time 
     // the values are changes via the keyup event 
     $("input[name^=avg]").avg({ 
      bind:"keyup" 
      , selector: "#totalAvg" 
      // if an invalid character is found, change the background color 
      , onParseError: function(){ 
       this.css("backgroundColor", "#cc0000") 
      } 
      // if the error has been cleared, reset the bgcolor 
      , onParseClear: function(){ 
       this.css("backgroundColor", ""); 
      } 
     }); 

     // automatically update the "#minNumber" field every time 
     // the values are changes via the keyup event 
     $("input[name^=min]").min("keyup", "#numberMin"); 

     // automatically update the "#minNumber" field every time 
     // the values are changes via the keyup event 
     $("input[name^=max]").max("keyup", { 
      selector: "#numberMax" 
      , oncalc: function (value, options){ 
       // you can use this to format the value 
       $(options.selector).val(value); 
      } 
     }); 

     // this calculates the sum for some text nodes 
     $("#idTotalTextSum").click(
      function(){ 
       // get the sum of the elements 
       var sum = $(".textSum").sum(); 

       // update the total 
       $("#totalTextSum").text("$" + sum.toString()); 
      } 
     ); 

     // this calculates the average for some text nodes 
     $("#idTotalTextAvg").click(
      function(){ 
       // get the average of the elements 
       var avg = $(".textAvg").avg(); 

       // update the total 
       $("#totalTextAvg").text(avg.toString()); 
      } 
     ); 
    } 
); 

function recalc(){ 


    $("[id^=total_item]").calc(
     // the equation to use for the calculation 

     if(qty > 24){ 

      "qty * price", 
     // define the variables used in the equation, these can be a jQuery object 
     { 
      qty: $("input[name^=qty_item_]"), 
      price: $("[id^=price_item_]"), 

     }, 

     }else{ 

      "qty = fee", 
     // define the variables used in the equation, these can be a jQuery object 
     { 
      qty: $("input[name^=qty_item_]"), 
      fee: ($("input[name^=qty_item_]").val() < 13) ? 19 : 37 , 

     }, 

     } 




     // define the formatting callback, the results of the calculation are passed to this function 
     function (s){ 
      // return the number as a dollar amount 
      return "£" + s.toFixed(2); 
     }, 
     // define the finish callback, this runs after the calculation has been complete 
     function ($this){ 
      // sum the total of the $("[id^=total_item]") selector 
      var sum = $this.sum(); 

      $("#grandTotal").text(
       // round the results to 2 digits 
       "£" + sum.toFixed(2) 
      ); 
     } 
    ); 
} 

심지어 시도 ... 내가 jQuery를위한 calculation plugin에 관심이

function recalc(){ 

     // define the variables used in the equation, these can be a jQuery object 
     var qty = $("input[name^=qty_item_]"); 
     var price = $("[id^=price_item_]"); 
     var fee = ($("input[name^=qty_item_]").val() < 13) ? 19 : 37; 

    $("[id^=total_item]").calc(
     // the equation to use for the calculation 

     if(qty > 24){ 

      "qty * price", 


     }else{ 

      "qty = fee", 

     } 
+0

안녕하세요, 내가 도와 싶습니다. HTML을 여기에 표시하거나 [jsFiddle] (http://www.jsfiddle.net)을 사용 하시겠습니까? 감사. – Paolo

+0

방법을 모르는 jsFiddle을 사용하고 위의 코드가 지저분 해 보이게 붙여 ... 내가 온라인으로 사용할 수있는 또 다른 코드 도구가 있습니까? –

+1

사실 ... 내가 JS 코드와 HTML과 자바 스크립트와 HTML의 영역을 채우고 그것을 밖으로 ... http://jsfiddle.net/Q3Nwd/ –

답변

0

자신 그래서 나는 같은 소스를 해결하기 위해 관리 운동. 그것이 당신이 좋아하는 방식으로 작동하는지 확인하고 코드를주의 깊게 읽으십시오.

링크 : http://jsfiddle.net/Q3Nwd/3/