2011-03-06 2 views
0

나는 우수한 jQuery 계산 플러그인을 http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm에서 사용했습니다. 하지만 jQuery가 폼에서 동적으로 생성되는 html 읽기 전용 입력 태그에 직접 값을 쓰도록 요구하는 CMS 폼 모듈 내에서 작동하도록 편집해야합니다.예약 양식 합계를 계산하시오

대신 위의 계산 플러그인에서 제공하는 기본 html 코드가 사용되었으며, 이는 매우 잘 작동합니다.

<td><TextBox name="childNumber" Id="childNumber" DataField="ChildPassengers" DataType="int32" /></td> 

:

$("input[id$='childTotal']").val('25.99') 

즉 아래에있는 내 HTML 코드의 샘플을 - 나는 가격 태그와 총 태그를 채울 출력을 가격 항목을 소요하고 전송하는 jQuery를 작성해야

아래는 jQuery 코드입니다 (작동하지 않음)

<script type="text/javascript"> 
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 input adult quantity fields 
     $("input[name^=adultNumber]").bind("keyup", recalc); 
     // run the calculation function now 
     recalc(); 
     // bind the recalc function to the input child quantity fields 
     $("input[name^=childNumber]").bind("keyup", recalc); 
     // run the calculation function now 
     recalc(); 

     $("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$=adultTotal]").calc(
     // the equation to use for the calculation 
     "Aqty * Aprice", 
     // define the variables used in the equation, these can be a jQuery object 
     { 
      Aqty: $("input[name$=adultNumber]"), 
      Aprice: $("input[id$='adultPrice']").val('50.99') 

       }, 
      var Atotal=Aqty * Aprice; 
      Atotal.toFixed(2); // two decimal places 
$('#adultTotal').html(Atotal.toFixed(2));    


    function recalc(){ 
    $("[id$=childTotal]").calc(
     // the equation to use for the calculation 
     "Cqty * Cprice =Csum", 

     { 
      Cqty: $("input[name$=childNumber]"), 
      Cprice: $("input[id$='childPrice']").val('25.99') 

       }, 
      var Ctotal=Cqty * Cprice; 
      Ctotal.toFixed(2); // two decimal places 
$('#childTotal').html(Ctotal.toFixed(2)); 




    function recalc(){ 
    $("[id$=grandTotal]").calc(

    var Grantotal=Atotal + Ctotal; 

     Grantotal.toFixed(2); // two decimal places 
$('#grandTotal').html(Gtotal.toFixed(2)); 

     } 
    ); 
} 
</script> 
+2

이것은 코드가 없으므로 "작동하지 않음"이라는 의미를 정확히 설명해야합니다. 함수 호출이나 실패한 줄로 좁힐 수 있습니까? –

+0

jQuery 플러그인을 많이 사용하는만큼 기본적인 산술 연산에는 사용하지 않습니다. 약간의 JavaScript 및 jQuery 선택기를 사용하면 JavaScript에서 기본 산술을 수행하는 데 문제가 없어야합니다. 그 일을해야한다는 생각이 들지 않는다면 자바 스크립트의 기초를 배우는데 더 많은 시간을 할애 할 것입니다. –

답변

0

나는 그쪽으로 생각합니다. 문제는`recalc '를 재정의했다는 것입니다. 각 기능에 고유 한 이름을 지정하십시오.

관련 문제