JavaScript未捕获类型错误非法调用

时间:2015-07-10 07:22:11

标签: javascript

var Rules = Rules || (function () {

    saverule = function () {
        var level = document.getElementById("level-selection");
            var metrics = document.getElementById("metric-selection");
            var operator = document.getElementById("operator-selection");
            var value = document.getElementById("value123");
            var saveAction = $("#hidden-save").val();
            $.post(saveAction, { level_id: level, product_id: metrics, opp: operator, value: value }, function () {


            },
                'json');
        };
    wireLinkActions = function () {

        $("a.save-ok").on("click", function(event) {
            saverule();
            return false;
        });
    };
    return {
        Initialize: function () {

            wireLinkActions();
        }
    }
})();

$(document).ready(Rules.Initialize);

非法调用错误,它甚至不会在调试时调用保存规则函数

1 个答案:

答案 0 :(得分:0)

确保返回值,而不是DOM元素本身 例如,改变这个:

var level = document.getElementById("level-selection");

进入这个:

var level = document.getElementById("level-selection").value;

或者,只需使用如下的jQuery:

var level = $("#level-selection").val();