【发布时间】:2011-03-21 09:01:01
【问题描述】:
下面的 jQuery 片段用于顶部有消息的页面,以及在其下方回复消息的所有 cmets。代码在 IE8/Chrome/Firefox 上的工作方式是它“折叠”了初始消息下方的所有 cmets,因此只有它们的主题出现。单击他们的主题,然后将初始消息替换为评论(即,它“伪造”了将每条评论放在自己的页面上的行为)。
问题是 IE6 拒绝使用代码;当 IE6 访问者登陆页面时,所有 cmets 都拒绝折叠,点击标题没有任何反应。
有谁知道如何纠正这个问题以使 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>
【问题讨论】:
-
你试过看这里吗:stackoverflow.com/questions/463800/…?
-
我有 - 我已经将 $(document) 更改为 jQuery 没有任何运气 - 谢谢你的建议
标签: jquery cross-browser internet-explorer-6