2010-07-27 124 views
0

下面的一段jQuery用在頂部有消息的頁面上,以及所有回覆下面消息的註釋。代碼在IE8/Chrome/Firefox上的工作方式是「摺疊」初始消息下面的所有評論,所以只顯示他們的主題。點擊他們的主題,然後用最初的消息替代評論(即它「僞裝」每個評論在自己的頁面上的行爲)。IE6不喜歡我簡單的jQuery:任何想法爲什麼?

問題是IE6拒絕使用代碼;當IE6訪問者登錄頁面時,所有評論拒絕崩潰,並且點擊標題無效。

有沒有人有任何想法如何糾正這個問題,使JS IE6兼容?

function flip(comment) { 
$('#first-post').replaceWith(comment.closest(".comment").clone().attr('id','first-post')); 
$('#first-post').children('.forumthreadtitle').children('.comment-info').empty(); 
$('#first-post').find(':hidden').fadeIn('slow'); 
$('html, body').animate({scrollTop:0}, 'fast'); 
return false; 
} 

$(document).ready(
function(){ 

$('.submitted').each(function() { 
$(this).clone().addClass('comment-info').appendTo($(this).siblings('.forumthreadtitle')); 
if(!$(this).parent('#first-post').html()) { 
    $('#first-post').children('span.taxonomy').clone().appendTo($(this)); 
    } 
}); 

$('.display_mode').html('Show All Replies'); 
expandedMode = false; 
$('.display_mode').click(function() { 
    if (expandedMode == false ) { 
     $('.forumthreadtitle').siblings().show(); 
     $(this).html('Collapse Replies'); 
     expandedMode = true; 
     } 
    else 
     { 
     $('.forumthreadtitle').siblings().hide(); 
     $(this).html('Show All Replies'); 
     expandedMode = false; 
     } 
    }); 

$('.forumthreadtitle').siblings().hide(); 

if(window.location.hash) { 
     flip($(window.location.hash).next().children('.forumthreadtitle').show()); 
     } 

$('.forumthreadtitle').click(function() { 
    pageTracker._trackPageview("/comment?page=" + document.location.pathname); 
    flip($(this)); 
    }); 
}); 

下面是一些例子HTML(試圖簡化它一點點,使其更容易理解):

<DIV id="first-post"> 
     <H2 class="title"><A href="test.html">TEST</A></H2> 
     <SPAN class="submitted">Submitted by Big J on July 26, 2010 - 3:26pm</SPAN> 
    <DIV class="content">First Post</DIV> 
</DIV> 

<DIV id="comments"> 
    <A id="comment-1643951"></A> 
<DIV class="comment comment-published clear-block"> 
    <H3 class="forumthreadtitle"><A href="test.html#comment-1643951" class="active">Test Reply....</A> 
    <DIV class="submitted comment-info">Submitted by test on July 26, 2010 - 4:49pm.</DIV> 
    </H3> 

    <DIV class="content" style="display: none; "> 
    Test Comment Content 
    </DIV> 
</DIV> 
</DIV> 
+0

你有沒有試過看這裏:http://stackoverflow.com/questions/463800/jquery-document-ready-failing-in-ie6? – nandokakimoto 2010-07-27 00:38:25

+0

我有 - 我沒有任何運氣改變$(文檔)jQuery - 謝謝你的建議 – 2010-07-27 02:42:36

回答

0

我建議你嘗試兩兩件事:

  1. 使用jQuery(function(){})而不是$(document).ready(function(){});
  2. 將您的jQuery代碼移動到HTML頁面的底部。
+0

謝謝你的建議!我現在會嘗試它們 – 2010-07-27 01:20:12

+0

我將$(文檔)更改爲jQuery,並且我的代碼已經在頁面的底部 - 仍然沒有效果:( – 2010-07-27 01:40:17

相關問題