2011-04-26 51 views
0

我使用了jQuery插件計算器(http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm),並計算成本時,遇到了一個小問題,都有所涉獵杯蛋糕。jQuery的計算不工作了

我需要1-12產品19£,爲13-24產品37£或每1.45£爲25+的產品,但無法工作,如何改變和展示這一點。

任何人都可以請幫忙嗎?

到目前爲止我的代碼...

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) 
      ); 
     } 
    ); 
} 

我甚至試過......

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 2011-04-27 12:09:14

+0

不知道如何使用的jsfiddle和粘貼上面的代碼,使它看起來凌亂...有另一種代碼的工具,我可以在網上使用? – 2011-04-27 12:16:24

+1

其實...我想我的工作了...... http://jsfiddle.net/Q3Nwd/ – 2011-04-27 12:19:55

回答