TypeError:fun不是函数

时间:2016-03-29 12:21:00

标签: javascript

当我打电话OpenModelWindow时,功能显示错误fun is not a function这里是我的功能代码

function OpenModelWindow(url, option) {

        var fun;
        try {
            if (parent != null && parent.$ != null && parent.$.ShowIfrmDailog != undefined) {
                fun = parent.$.ShowIfrmDailog
            }
            else {
                fun = $.ShowIfrmDailog;
            }
        }
        catch (e) {
            fun = $.ShowIfrmDailog;
        }
        fun(url, option);
    }

1 个答案:

答案 0 :(得分:0)

那是因为fun可能是未定义的。要解决此问题,请检查fun的类型:

function OpenModelWindow(url, option) {

    var fun;
    try {
        if (parent != null && parent.$ != null && parent.$.ShowIfrmDailog != undefined) {
            fun = parent.$.ShowIfrmDailog
        }
        else {
            fun = $.ShowIfrmDailog;
        }
    }
    catch (e) {
        fun = $.ShowIfrmDailog;
    }
    if (typeof fun == 'function') // <----
        fun(url, option);
}