如何解决Uncaught TypeError:无法读取属性' addEventListener'为null

时间:2015-07-16 05:50:49

标签: javascript google-chrome

我在Chrome浏览器中遇到错误,在运行Web应用程序时,但在IE中,应用程序运行正常。 请建议。

var cb_addEventListener = function(obj, evt, fnc) {
    // W3C model
    if (obj.addEventListener) {
        obj.addEventListener(evt, fnc, false);
        return true;
    } 
    // Microsoft model
    else if (obj.attachEvent) {
        return obj.attachEvent('on' + evt, fnc);
    }
    // Browser don't support W3C or MSFT model, go on with traditional
    else {
        evt = 'on'+evt;
        if(typeof obj[evt] === 'function'){
            // Object already has a function on traditional
            // Let's wrap it with our own function inside another function
            fnc = (function(f1,f2){
                return function(){
                    f1.apply(this,arguments);
                    f2.apply(this,arguments);
                }
            })(obj[evt], fnc);
        }
        obj[evt] = fnc;
        return true;
    }
    return false;
};

var myForm = document.getElementById("prsregistrationform");
cb_addEventListener( myForm, 'submit', function() {
    return validateForm(document.partnerSimulationForm, document.prsregistrationform);
});

0 个答案:

没有答案