我創建了一個包含多個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工具,但沒有錯誤。
請分享jsfiddle。 – 2012-08-08 17:01:58
「這是在我的頭標籤,我已經複製了3次,所以它總共工作4個div」。呸。只需給所有的div一個普通的類名,然後將行爲應用到類中,而不是通過ID將其應用到每個元素。 – Madbreaks 2012-08-08 17:04:50