【问题标题】:How to take data .on change function?如何获取数据 .on 更改功能?
【发布时间】:2017-02-20 10:50:48
【问题描述】:

我在 MVC 视图中有这个功能:

 $(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' 字段中输入的更改值数据。

【问题讨论】:

  • 可能#y 不是一个可以取值的元素……但你没有提供minimal reproducible example 所以很难说。
  • 为什么问题没有用jquery标记你的意思是忘记加载jquery或任何其他resson??
  • 有人解决这个问题吗?
  • 谢谢你,我也标记了 jquery。
  • @HelmerRashiti — 我们无法通过minimal reproducible example为您提供解决方案

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


【解决方案1】:

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

$(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.") + " €");
                        });

                    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 2018-08-20
    • 2018-12-05
    • 1970-01-01
    • 2012-03-31
    • 2017-10-09
    • 1970-01-01
    相关资源
    最近更新 更多