【问题标题】:jQuery - Input field calculation not working in Chrome and SafarijQuery - 输入字段计算在 Chrome 和 Safari 中不起作用
【发布时间】:2011-10-14 23:12:40
【问题描述】:

我有一个表单,其中的字段在添加值时会自动总计,它在 6,7 +8 和 FF 中运行良好,但在 Safari 和 Chrome 中该字段为空白 - 有什么想法吗??

// total income
    jQuery(document).ready(function(){

        jQuery("input.add").change(function () {
            var sum = 0;
            jQuery('.add').each(function() {
                var Total = sum += Number(jQuery(this).val());
                jQuery("#input_38").val(Total);

});

        });​​​​​​​​​ <---  Chrome has a problem with this 'Unexpected token ILLEGAL'


        // total expenditure
        jQuery("input.add_ex").change(function () {
            var sumEx = 0;
            jQuery('.add_ex').each(function() {
                var TotalEx = sumEx += Number(jQuery(this).val());
                jQuery("#input_70").val(TotalEx);
            });


        });​​​​​​​​​

        //grand total

        jQuery("input.add_ex").change(function () {                 // when total expenditure field changes

            var totalInc = Number(jQuery("#input_38").val()); // store total income as var
            var totalExp = Number(jQuery("#input_70").val()); // store total expenditure as var

            jQuery("#input_75").val(totalInc - totalExp); // change grand total

        });




    });//end

【问题讨论】:

  • 你的代码对我来说很好here。您的控制台是否出现任何错误?
  • 具体是哪个领域?你在控制台中有任何错误吗?您也可以发布您的 html 的 sn-p 吗?
  • @Nalum - 在 chrome 或 firebug 中根本没有
  • @mamoo - 上面的小提琴有基础知识,它只是汇总了 '.add' 和 '.add_ex' 类的字段
  • 已解决:从Mac切换到PC记事本,发现一堆需要删除的随机字符,现在可以了。

标签: jquery google-chrome safari cross-browser


【解决方案1】:

由于 Nalum 的示例正在运行,因此某些隐藏字符可能会弄乱您的脚本。

尝试使用JSLint 看看它是否发现了相同的问题,并尝试删除该行中的一些空格。

编辑:

我发现了一个类似的问题here

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 2023-03-29
    • 2011-02-20
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多