Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何取消选择告诉您哪个选项已更改的参数?如何获得正确的JQuery和Javascript总价?_Javascript_Jquery - Fatal编程技术网

如何取消选择告诉您哪个选项已更改的参数?如何获得正确的JQuery和Javascript总价?

如何取消选择告诉您哪个选项已更改的参数?如何获得正确的JQuery和Javascript总价?,javascript,jquery,Javascript,Jquery,您将看到示例代码 以下是我的问题: -我必须选择有价值的服务,但是当我取消这些服务时,总价格会上升而不是下降。 -在我测试之后,我取消了所有的服务,但是总价格仍然存在。我怎样才能把它恢复到零 谢谢 以下是我的示例代码: $(".chzn-select").chosen(); $("#cboservices").on("change", function(evt, params){ alert($(this).

您将看到示例代码

以下是我的问题: -我必须选择有价值的服务,但是当我取消这些服务时,总价格会上升而不是下降。 -在我测试之后,我取消了所有的服务,但是总价格仍然存在。我怎样才能把它恢复到零

谢谢

以下是我的示例代码:

$(".chzn-select").chosen();
                    $("#cboservices").on("change", function(evt, params){
                        alert($(this).val());
                        //console.log($(this).val());
                        parray = $(this).val();
                        for (pcode in parray) {
                            get_priceList(parray[pcode]);
                            //console.log(sprice * totaltime);
                            tprice = tprice + (sprice * totaltime);
                        }

                        $("#subTotalPrice").html(number_format(tprice, 2, ".", ""));
                        console.log($("#subTotalPrice").html());            
                    });



                }
            },



Below are the sample HTML. I can't paste the whole code because it has limit. Thank you for the quick reply.


reservationDetails =
        '<div id="modal_div" class="widgets">'+
        '        <div class="widget widgetFix">'+
        '            <div class="title"><img src="images/icons/color/user-silhouette-question.png" alt="" class="titleIcon" /><h6>Information</h6></div>'+
        '            <br />'+
        '                <div id="refdiv" class="formRow modalFix">'+
        '                    <label>Reference No:</label>'+
        '                    <div class="formRight"><label class="labelFix inputFix" id="refNoValue">0</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix">'+
        '                    <label>Room No:</label>'+
        '                    <div class="formRight"><label class="labelFix inputFix" id="roomNoValue">0</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix">'+
        '                    <label>Name:</label>'+
        '                    <div class="formRight"><input type="text" id="customerNameValue" name="customerNameValue"/></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+

        '                <div class="formRow modalFix">'+
        '                <label>Services:</label>'+
        '                    <div class="formRight labelFix">'+
        '                        <select id="cboservices" data-placeholder="Choose your service(s)..." class="chzn-select" multiple="multiple" tabindex="6">'+
        '                       </select>'+  
        '                    </div>'+ 
        '                </div>'+ 

        '                <div class="formRow modalFix">'+
        '                    <label>Price:</label>'+
        '                    <div class="formRight"><label class="labelFix inputFix" id="subTotalPrice">0.00</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+

        '                <div class="clear"></div>'+ 

        '                <div class="formRow modalFix">'+
        '                <label>Personnel:</label>'+
        '                    <div class="formRight labelFix">'+
        '                        <select id="cbopersonnels" data-placeholder="Choose your attendant(s)..." class="chzn-select" multiple="multiple" tabindex="6">'+
        '                       </select>'+  
        '                    </div>'+ 
        '                </div>'+ 
        '                <div class="clear"></div>'+ 

        '                <div class="formRow modalFix">'+
        '                    <label>Date:</label>'+
        '                    <div class="formRight"><label class="labelFix inputFix" id="dateValue">0</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix">'+
        '                     <label>Start Time:</label>'+
        '                     <div class="formRight"><label class="labelFix inputFix" id="startTimeValue">0</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix">'+
        '                    <label>End Time:</label>'+
        '                    <div class="formRight"><label class="labelFix inputFix" id="endTimeValue">0</label></div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix">'+
        '                    <label>Status</label>'+
        '                    <div class="formRight ">'+
        '                        <select id="statusValue" name="statusValue">'+
        '                           <option value="reserved">Reserved</option>'+
        '                           <option value="paid">Paid</option>'+
        '                        </select>'+
        '                    </div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '                <div class="formRow modalFix" style="margin-top:3px">'+
        '                    <label>Remarks</label>'+
        '                    <div id="remarksdiv" class="formRight ">'+
        '                        <textarea id="remarksValue" name="remarksValue" style="resize:none;"></textarea>'+
        '                    </div>'+
        '                    <div class="clear"></div>'+
        '                </div>'+
        '            <br />'+
        '        </div>'+  
        '    <div class="clear"></div>'+
        '</div>';
而不是你的

for(something in something){ ... }
本质上,您需要的东西如下所示:

// Define subtotal outside of loop
subtotal = 0

// This is like your for() loop
$('.price_element_selector').map(function(el){

  // get the individual price of each cart item
  price = parseFloat($(el).val())

  subtotal += price

});

formatMoney(subtotal);
而不是你的

for(something in something){ ... }
本质上,您需要的东西如下所示:

// Define subtotal outside of loop
subtotal = 0

// This is like your for() loop
$('.price_element_selector').map(function(el){

  // get the individual price of each cart item
  price = parseFloat($(el).val())

  subtotal += price

});

formatMoney(subtotal);

每次进入循环时,必须首先将“金额”值设置为0

例如:

$("#cboservices").on("change", function(evt, params){
    alert($(this).val());
    //console.log($(this).val());
    parray = $(this).val();
    tprice = 0; //insert this line <<<<<<<<<<<<<<<<<=====[xxx]
    for (pcode in parray) {
        get_priceList(parray[pcode]);
        //console.log(sprice * totaltime);
        tprice = tprice + (sprice * totaltime);
    }

$("#subTotalPrice").html(number_format(tprice, 2, ".", ""));
console.log($("#subTotalPrice").html()); 


});

每次选择和/或取消选择标记上的元素时调用。

每次进入循环时,必须首先将“金额”值设置为0

例如:

$("#cboservices").on("change", function(evt, params){
    alert($(this).val());
    //console.log($(this).val());
    parray = $(this).val();
    tprice = 0; //insert this line <<<<<<<<<<<<<<<<<=====[xxx]
    for (pcode in parray) {
        get_priceList(parray[pcode]);
        //console.log(sprice * totaltime);
        tprice = tprice + (sprice * totaltime);
    }

$("#subTotalPrice").html(number_format(tprice, 2, ".", ""));
console.log($("#subTotalPrice").html()); 


});

每次您选择和/或取消选择标签上的元素时,都会调用。

提供html标记或在以下位置摆弄:您可以创建演示吗?您应该包括在取消服务时降低价格的代码。您好!我已经编辑了代码,但是我不能粘贴整个代码。@BarbaraPM谢谢你的回复。我试着这样做,但仍然无法得到正确的结果。提供html标记或在以下位置进行修改:你能创建一个演示吗?你应该包括在取消服务时降低价格的代码。你好!我已经编辑了代码,但是我不能粘贴整个代码。@BarbaraPM谢谢你的回复。我试着这么做,但仍然不能得到正确的结果。