2013-01-21 35 views
1

我有一個覆蓋網頁,我有一個父DIV和兒童DIV這樣的div不能可見

<div id="completeBlock" style="display:block"> 
    <div id="id1" style="display:block"> 
     This is div one 
    </div> 
    <div id="id2" style="display:none"> 
     This is div two 
    </div> 
     <div id="id3" style="display:none"> 
     This is div three 
    </div> 
</div> 

和獨立的鏈接顯示的div

<a onclick=doChangeDiv(id1)>link one</a> 
<a onclick=doChangeDiv(id2)>link two</a> 
<a onclick=doChangeDiv(id3)>link three</a> 

我的目的是要表明一次一個div,使其他人none.It在所有瀏覽器中都能正常工作,但在Firefox第一次打開頁面時工作正常。如果我關閉頁面並再次打開, 隱藏的div無法顯示我得到一個錯誤「TypeError:無法訪問死對象T」

我的jQuery腳本是

function doChangeDiv(fromId){ 
$('#completeBlock').children().each(function() { 
     if($(this).css('display') != 'none') 
     { 
      var hideId = '#'+$(this).attr('id'); 
      $(hideId).hide(); 
     } 
    }); 
    $(fromId).attr('display','block'); 
    $(fromId).show(); 
} 

請幫我理清這個問題。

回答

0

看到這個:http://jsfiddle.net/uD9mU/1/

$(document).ready(function() { 

$('a').click(function (e) { 
    e.preventDefault(); 
    var fromId = $(this).attr("data"); 
    //alert(fromId); 
    $('#completeBlock').children().hide().filter('#'+fromId).fadeIn('slow'); 
}); 

}); 
+0

感謝您的答覆它的工作原理fine.But事情是我有不同類別超過3個錨標記,而我想這個點擊事件和一些錨標籤綁定我不想綁定這個點擊事件。是否有任何方法將相同的事件綁定到不同的類上 – user1934095

+0

如果你有帶類「a1」,「b1」,「c1」的錨標籤,則使用'$('a.a1 ,a.b1,a.c1')。click(...);' – Anujith

+0

非常感謝你 – user1934095