计算预订表格总数

时间:2011-03-06 22:20:27

标签: jquery html input

我使用了http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm中出色的jQuery Calculation插件。但是我需要编辑它才能在CMS表单模块中工作,这需要jQuery将我想要的值直接写入在表单上动态创建的html只读输入标记。

而不是上面的计算插件提供的默认html代码,它开箱即用。我需要编写一个jQuery,它接受价格项并发送输出以填充价格标签和总标签 - 即。

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

我的html代码示例如下:

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

    

下面是我的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>

1 个答案:

答案 0 :(得分:0)

我认为你的问题是你重新定义了'recalc'。为每个函数指定一个唯一的名称。