Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';我得到一个';第0'行的堆栈溢出;当我使用简单的Javascript函数时,IE8中出现错误。如何修复此错误?_Javascript_Html_Internet Explorer_Internet Explorer 8 - Fatal编程技术网

I';我得到一个';第0'行的堆栈溢出;当我使用简单的Javascript函数时,IE8中出现错误。如何修复此错误?

I';我得到一个';第0'行的堆栈溢出;当我使用简单的Javascript函数时,IE8中出现错误。如何修复此错误?,javascript,html,internet-explorer,internet-explorer-8,Javascript,Html,Internet Explorer,Internet Explorer 8,以下是函数: function LoadBanner(img) { var d = new Date(); var Today = d.getDate(); var Month = d.getMonth(); Month++; //Months are 0 based var src; if (Month === 8 && (Today >= 1 && Today

以下是函数:

function LoadBanner(img) {
        var d = new Date();
        var Today = d.getDate();
        var Month = d.getMonth();
        Month++; //Months are 0 based
        var src;
        if (Month === 8 && (Today >= 1 && Today <= 17)) {
            src = "banner1.jpg";
        } else if (Month === 8 && (Today >= 18 && Today <= 31)) {
            src = "banner3.jpg";
        } else if (Month === 9 && (Today >= 1 && Today <= 7)) {
            src = "banner2.jpg";
        } else if (Month === 9 && (Today >= 8 && Today <= 14)) {
            src = "banner5.jpg";
        } else if (Month == 9 && (Today >= 15 && Today <= 21)) {
            src = "banner4.jpg";
        } else if (Month == 9 && (Today >= 22 && Today <= 28)) {
            src = "banner6.jpg";
        } else if (Month == 9 && (Today >= 29 && Today <= 30)) {
            src = "banner7.jpg";
        } else {
            document.getElementById("bannerdiv").style.display = "none";
        }

        img.src = src;
    }
功能加载横幅(img){
var d=新日期();
var Today=d.getDate();
var Month=d.getMonth();
Month++;//月份以0为基础
var-src;

如果(月===8&&(今天>=1&&Today=18&&Today=1&&Today=8&&Today=15&&Today=22&&Today=29&&Today您正在更改图像的源,强制其重新加载并触发重新加载

可能最快的修复方法是:

if (img.src != src) {
    img.src = src;
}

避免在src没有改变的情况下重新加载。我猜以后的浏览器已经内置了这个检查,但是即使是那些浏览器也会运行你的
onload
处理程序两次。

你正在改变图像的来源,强迫它重新加载并再次触发
onload
。明白了!如果你作为答案发布,我会接受信息技术
if (img.src != src) {
    img.src = src;
}