如何获取数据.on更改功能?

时间:2017-02-20 10:50:48

标签: javascript jquery ajax forms model-view-controller

我在MVC View中有这个功能:

 $(document).ready(function() {
    colSum55();
});

function colSum55() {
    var sumPP = 0;
    var x = ($("[name='popust']").val());
    var t = 0;

    $(".Total").each(function() {
        sumPP += parseFloat($(this).text());
    });
    t = (((sumPP) - ((sumPP) * (x / 100))));
    var y = 0;
    y = ($('#TotalPPO1').val((t).toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.") + " €"));
}
$(function() {

    $("[name='popust']").on("change", function() {

        $("#TotalPPO").val($("#y").val());

    });
}); 

在这个函数$(“#y”)。val()不占用数据,问题出在哪里?   我想在 name ='popust'字段中输入更改值的数据。

1 个答案:

答案 0 :(得分:0)

我解决了,这是我需要的解决方案:

$(document).ready(function () {
                    colSum55();
                });
function colSum55() {
                        $("[name='popust']").on("change", function () {
                            var pp = 0;
                            pp = $("#popust1").val($(this).val());

                        var sumPP = 0;
                        var x = ($(pp).val());
                        var t = 0;
                        var y = 0;
                        //iterate through each input and add to sum
                        $(".Total").each(function () {
                            sumPP += parseFloat($(this).text());
                        });
                        t = (((sumPP) - ((sumPP) * (x / 100))));
                         $('#TotalPPO').html((t).toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.") + " €");
                        });

                    }