IE7不响应JavaScript DOM元素

时间:2019-05-17 17:13:46

标签: javascript internet-explorer

当循环查找p标记中的某些文本时,IE7无法识别Javascript中的DOM元素。

我有以下脚本可以在IE9 +和Chrome中正常运行:

var healthPlanName = '<%=oAEAuthInfo.GetInfo("HealthPlan_Name")%>';
var plntp = '<%=oAEAuthInfo.GetInfo("PlanType")%>';
var lcd = '<%=oAEAuthInfo.GetInfo("LanguageCodeID")%>';

console.log(healthPlanName);

    //SENIOR
if(plntp === "3" || plntp === "10"){
    modifyDenialReasonSR();
}

function modifyDenialReasonSR(){        

    var ps = document.getElementsByTagName('p'), len = ps.length; console.log(ps);

    if(healthPlanName === "UnitedHealthcare"){      
        for (var i = 0; i < len; ++i) {

            //ENGLISH
            if(lcd === "65"){   
                if(ps[i].innerHTML.indexOf("Why did we deny your request?") !== -1) {
                    var e = ps[i], d = document.createElement('div');

                    d.innerHTML = e.innerHTML;

                    e.parentNode.insertBefore(d, e);
                    e.parentNode.removeChild(e);

                    d.removeAttribute('style');
                    d.setAttribute("id", "modifyAuthCSSUnited");    
                }
            }

            //SPANISH
            if(lcd === "66"){   
                if(ps[i].innerHTML.indexOf("¿Por qué hemos denegado la petición?") !== -1) {
                    var e = ps[i], d = document.createElement('div');

                    d.innerHTML = e.innerHTML;

                    e.parentNode.insertBefore(d, e);
                    e.parentNode.removeChild(e);

                    d.removeAttribute('style');
                    d.setAttribute("id", "modifyAuthCSSUnited");    
                }
            }

        }   
    }
}

我知道我可以使用以下元标记来强制用户的IE浏览器使用IE9(“ meta http-equiv =“ X-UA-Compatible” content =“ IE = edge”“)。但是,最终,我无法访问用于生成文档打印视图的文件。

还有另一种方法可以实现我想做的事情。

@Moob:我在aspx文件中添加了以下内容。调用aspx文件时,仍无法识别indexOf:

<script>

var healthPlanName = '<%=oAEAuthInfo.GetInfo("HealthPlan_Name")%>';
var plntp = '<%=oAEAuthInfo.GetInfo("PlanType")%>';
var lcd = '<%=oAEAuthInfo.GetInfo("LanguageCodeID")%>';

//SENIOR
if(plntp === "3" || plntp === "10"){
    modifyDenialReasonSR();
}

function modifyDenialReasonSR(){        

    var ps = document.getElementsByTagName('p'), len = ps.length; console.log(ps);

    if(healthPlanName === "UnitedHealthcare"){      
        for (var i = 0; i < len; ++i) {

            //ENGLISH
            if(lcd === "65"){   
                alert('hi2');
                if(ps[i].innerHTML.indexOf("Why did we deny your request?") !== -1) {
                    var e = ps[i], d = document.createElement('div');

                    d.innerHTML = e.innerHTML;

                    e.parentNode.insertBefore(d, e);
                    e.parentNode.removeChild(e);

                    d.removeAttribute('style');
                    d.setAttribute("id", "modifyAuthCSSUnited");                    
                }
            }

        }   
    }
}


document.addEventListener("DOMContentLoaded", function(event) {
    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function(obj, start) {
            for (var i = (start || 0), j = this.length; i < j; i++) {
                if (this[i] === obj) {
                    return i;
                }
            }
            return -1;
        };
    }

    if(typeof String.prototype.trim !== 'function') {
        String.prototype.trim = function() {
            return this.replace(/^\s+|\s+$/g, '');
        };
    };
});

0 个答案:

没有答案
相关问题