2012-11-27 154 views
3

我有一個問題在IE8:特定於IE8的JavaScript錯誤?

function costructor(sectionId){ 
$('#nextG').ready(function(){ 
var counterBis = 0; 
slider = '.slider0'+sectionId; 
//sliderBox = $(slider).closest('.floatContent'); 
unitScrollBis = $(slider).find('.floatImg').eq(0).width(); 
maxImg = $(slider).find('.floatImg').length-2; 
    /*problem*/ 
prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 
    /*END*/ 
console.log(prev); 
console.log(next); 
makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg); 
function makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg){ 
if(counterBis <= 0){ 
    $(prev).fadeOut("fast"); 
} 
else if(counterBis >= maxImg){ 
    $(next).fadeOut("fast"); 
} 
$(next).click(function(){ 
    if(counterBis <= maxImg){ 
     counterBis++; 
     $(prev).fadeIn("fast"); 
     slide(counterBis); 
     } 
    else{ 
     $(next).fadeOut("fast"); 
    } 
}); 
$(prev).click(function(){ 
    if(counterBis > 0){ 
     counterBis--; 
     $(next).fadeIn("fast"); 
     slide(counterBis); 
    } 
    else{ 
     $(prev).fadeOut("fast"); 
    } 
}); 
function slide(counterBis){ 
    $(slider).animate({ 
    marginLeft: '-' + (unitScrollBis*counterBis) + 'px' 
},1000); 
}; 
}; 

IE8說:SCRIPT438: Object doesn't support property or method誰能幫助我? 該問題只在IE8中,我不明白爲什麼IE不能建立這個字符串。 感謝您的幫助

+0

嘿!考慮讓我知道我的答案是否幫助你:)謝謝! – lifetimes

回答

3

您需要使用var關鍵字聲明變量,否則舊版本的IE將無法識別它們並可能中斷。

因此改變

prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 

var prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 
var next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id"); 

,一切都應該工作,因爲它在其他瀏覽器確實/ IE9

+1

謝謝解決的問題,即> 8沒有這個問題,還有其他的瀏覽器。我對你有個問題:'爲什麼有些開發者不使用關鍵字var來處理一些變量?' – ghost

+0

@ user1856813對不起,我的意思是提到它就像是一個IE8之前的問題,IE9 +和其他人很好,沒有它感謝。 – lifetimes

+0

關於你的問題,看看這個問題,它的答案 - http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript – lifetimes