2012-08-08 38 views
2

我創建了一個包含多個div的頁面,我想切換到相同的位置。這在Chrome和Firefox中正常工作,但按預期不在Internet Explorer中。我在一個頁面上使用了相同的方法,它工作正常,但是當我在另一個頁面上覆制它以使用多個div時,它會中斷。jquery顯示/隱藏在互聯網瀏覽器中破解的觸發器

的jQuery是:

<script type="text/javascript"> 
$(document).ready(function(){ 

//Hide the box  
    $("#sub1").hide(); 


//Sets up the click function and speed 
    $("#btn-slide").click(function(){ 
    $("#sub1").slideToggle("slow",function(){ 



//Toggles link text between open and close 
//=="Open" or as changed here to "VIEW DR. MARTENS HISTORY" is vital in order to close the box 
($("#btn-slide").html()=="| THE PUNK SCENE |")?$("#btn-slide").html("Close"):$("#btn-slide").html("| THE PUNK SCENE |"); 



    }); 
    return false; 
}); 
</script> 

這是在我的頭上的標籤,我已經重複3次,有工作在總共4個格。我已經改變了#BTN-幻燈片#BTN-滑件等

的HTML是:

<div id="move"><a href="#" title="| THE PUNK SCENE |" id="btn-slide" >| THE PUNK SCENE |</a></div> 

這是點擊打開隱藏的div的鏈接。再次,我有更多的這些divs與不同的div ID調用不同的#btn-slide。

這是一個正在被打開了DIV的HTML:

<div id="sub1"><strong>The Punk scene</strong> -and 2nd Generation Skins<br /> 
    <br /> 
    Following the Skins the Punk scene was a well known youth subculture to wear Dr. Martens. When Punk became known in the late 70's a second generation of Skins derived from the Punk scene. The media have often portrayed the 2nd gen Skin over the years, with the popular opinion of Skinhead culture being a 14 hole Dr. Marten (and white laces wearing) aggressive young white male. Fascist parties sourced new recruits from football games and amongst a violent throng of spectators some new recruits were Skins. <br /> 
     </div> 

我希望這是有道理的人有關於如何讓IE瀏覽器兼容的任何想法。我在IE上使用了f12工具,但沒有錯誤。

+0

請分享jsfiddle。 – 2012-08-08 17:01:58

+0

「這是在我的頭標籤,我已經複製了3次,所以它總共工作4個div」。呸。只需給所有的div一個普通的類名,然後將行爲應用到類中,而不是通過ID將其應用到每個元素。 – Madbreaks 2012-08-08 17:04:50

回答

1

您錯過了一些右括號。

這裏的小提琴:http://jsfiddle.net/esRFt/7/

這似乎很好地工作與IE8。它與哪個版本有關係?

+0

我有IE 9,它似乎無法正常打開和關閉:) – 2012-08-09 15:29:28

+0

我看着jsfiddle鏈接,原來是:|我用過的鍵盤虛線 - 「| THE PUNK SCENE |」。 謝謝你看看並提到jsfiddle鏈接,我認爲它會是這樣的小東西...... :-) – 2012-08-09 16:50:24

0

jQuery的html()函數在內部調用.innerHTML,這在IE中被稱爲是bug。您應該在三元條件下使用不同的測試(例如hasClass())。

+0

感謝您的答案球員,非常感謝:-) – 2012-08-09 16:52:03