好吧,我很難過。基本上,這個腳本在FF中工作正常,但不在IE(6,7或8)中 - 它返回一個「Object不支持這個屬性或方法」的錯誤。任何想法?:IE中的jQuery/AJAX:對象不支持這個屬性或方法
function portfolioAjaxLoader(page){
$("div#portfolio_container").load("include/DCK_portfolio_gallery.inc.php?cat=" + page);
}
$(document).ready(function(){
$('a.portfolio_subnav').livequery('click',function(){
portfolioAjaxLoader(this.title);
return false;
});
//modify page DOM if Javascript is switched on
$('div#gallery_frame').livequery(function(){
//assign portfolioAjaxLoader to sub navigation links
gallery_frame = $('div#gallery_frame');
//set gallery_strip width to the number of entries multiplied by width of gallery entry element
gallery_strip = $('div#gallery_strip');
gallery_entries = $('div#gallery_strip a');
elementWidth = 235;
gallery_strip_width = elementWidth*gallery_entries.length+'px';
gallery_strip.css({'width':gallery_strip_width});
//add portfolio navigation buttons
if(gallery_entries.length>4){
$('div#portfolio_nav').before('<p id="portfolio_nav_prev"></p><p id="portfolio_nav_next"></p>');
}
//assign event triggers to inserted portfolio nav elements
prev = $("p#portfolio_nav_prev");
next = $("p#portfolio_nav_next");
scrollPrevMax = (((gallery_entries.length - 4) * elementWidth)+20);//tolerance
scrollMax = ((gallery_entries.length - 5) * elementWidth);
scrollMin = ((gallery_entries.length - 6) * elementWidth);
});
function nextAnim(){
//remove handler
next.unbind();
var currentScrollPos = gallery_frame.scrollLeft();
var targetPos = currentScrollPos + elementWidth;
if(currentScrollPos > scrollMin){
next.fadeOut("fast");
}
if(currentScrollPos >= 0){
prev.fadeIn("fast");
}
gallery_frame.animate({scrollLeft:targetPos}, 300, 'easeInOutQuart',function(){next.bind('click',nextAnim)});
return false;
}
function prevAnim(){
//remove handler
prev.unbind();
var currentScrollPos = gallery_frame.scrollLeft();
var targetPos = currentScrollPos - elementWidth;
if(currentScrollPos < scrollPrevMax){
next.fadeIn("fast");
}
if((currentScrollPos == 0)||(currentScrollPos < elementWidth*2)){
prev.fadeOut("fast");
}
gallery_frame.animate({scrollLeft:targetPos}, 300, 'easeInOutQuart',function(){prev.bind('click',prevAnim)});
//prev.bind('click',prevAnim);
return false;
}
next.click(nextAnim);
prev.click(prevAnim);
});
我特意在全局範圍內留下了一些元素(通過在其聲明中省略var)。
只是爲了記錄在案,它報告錯誤的位置:
gallery_frame = $('div#gallery_frame');
字9號線,16
哪條線/部分代碼拋出錯誤? – BalusC
修改了條目,對不起。 – sunwukung