2010-09-10 33 views
0

http://dev.mindboiler.lv/(你會被帶到介紹頁面,只需點擊標識進入真正的網站)jQuery腳本在IE和Opera失敗

這是網站,我目前的工作。您可以將語言更改爲英語以更好地理解它,但無論如何,它都是虛擬文本。
有這些Read more鏈接,點擊後,執行下面的jQuery:

$('.content-item .readmore').toggle(function() { 
    parent = $(this).parent(); 
    $(parent).children('div.next').fadeIn(); 
    $(this).html("Read less »"); 
}, function() { 
    parent = $(this).parent(); 
    $(parent).children('div.next').fadeOut(); 
    $(this).html("Read more »"); 
}); 

火狐,Safari,Chrome的工作就像一個魅力,不過IE(所有版本)和Opera不希望執行它正常。

任何解決方案,以在IE和Opera工作?

P.S.不是JavaScript/jQuery大師,因此該腳本看起來像垃圾。

在此先感謝!

+0

有時候,如果事情不能在IE _and_歌劇院工作,這是一個跡象表明,你的標記結構是錯誤的,而不是腳本(如果它只在IE中不起作用,這可能表明您正在編寫出色的符合標準的代碼。)您是否驗證了該頁面? http://validator.w3.org – 2010-09-10 14:10:46

回答

1

它看起來好像你的<div class="next">是你的<div class="content-item">的兄弟姐妹,所以爲什麼甚至會打擾parent()函數。

它簡化到這一點,看看它是否工作:

$('.content-item .readmore').toggle(function() {   
    $(this).next().fadeIn(); 
    $(this).html("Read less &raquo;"); 
}, function() { 
    $(this).next().fadeOut(); 
    $(this).html("Read more &raquo;"); 
}); 
+0

由於'Read more'鏈接是'.content-item'的最後一個子元素,它不會與'.next()'一起工作,但是,將它改爲'.prev ()'做到了!感謝您指出正確的方向,接受! – jolt 2010-09-10 14:13:35