0
我有一些JavaScript(1.7.2)在一個外部的.js文件工作正常。但在IE兼容模式下檢查以確保它與IE7 +一起使用後,我遇到了一個問題。在頁面加載時調用的函數loader()中,調用chooseImage(img)可防止後續調用timeImgChange()。如果我改變這兩個調用的順序,那麼chooseImage()不會被調用,問題依然存在。希望有人能幫助,尼爾。IE兼容模式JavaScript函數不叫
window.onload = loader;
function loader(){
var img = document.getElementById('selector_chicks');
chooseImage(img); //This function call works
timeImgChange(); //Not called. Works in IE9. Is called if chooseImage() is removed
}
function chooseImage(img){
document.getElementById('chooseimage').src = imageMap[img.title].path;
document.getElementById(img.id).style.background = "#A66B00";
document.getElementById('textselected').innerHTML = imageMap[img.title].text;
/*unselect the other divs*/
var selectors = document.getElementsByClassName('selector');
for (var i = 0; i < selectors.length; i++){
if (selectors[i].title != img.title){
selectors[i].style.background = "#261e1e";
}
}
}
function timeImgChange() { /*Change the image ever x milliseconds*/
var imgIdArray = ["selector_egg", "selector_chicks", "selector_poults"];
var n = 1;
setInterval(function(){
if (doImageCycle){
var img = document.getElementById(imgIdArray[n]);
chooseImage(img);
n++;
if (n > 2) {n = 0;}
}
}, 2000);
}
哈哈!非常感謝你。 – nrhorner 2012-04-19 12:46:12
謝謝你提醒我。 – nrhorner 2012-04-19 14:16:16