2012-04-19 81 views
0

這是經典的iframe代碼。我想要的是當你點擊不同的鏈接時顯示不同的東西。是否可以使用iframe而不鏈接另一頁

我想在不同鏈接的頁面上在wordpress中顯示不同的畫廊。我不想代碼不同的HTML的爲他們每個人

<iframe id="myIframe" src="about:blank" height="200" width="500"></iframe> 
<br /> 
<a href="http://www.blogger.com" target="myIframe">Blogger</a><br /> 
<a href="http://www.cnn.com" target="myIframe">CNN</a><br /> 
<a href="http://www.google.com" target="myIframe">Google</a><br /> 
+0

如果你只是想顯示的字的博客我沒有看到在使用'iframe'的理由第一名 – PeeHaa 2012-04-19 21:52:42

+0

我想在不同鏈接的頁面上在wordpress中顯示不同的畫廊。我不想爲他們每個人編碼不同的html。 – Reis 2012-04-19 21:54:17

回答

2

的是什麼,你正在試圖做的是顯示和隱藏一個鏈接,當點擊該頁面的特定部分。你不需要爲此使用iframe。我想你最好使用隱藏的div,或者甚至可以使用ajax來加載不同的畫廊。我會告訴你隱藏的div的方法:

<div id="gallery1" class="gallery"> 
    A whole lot of html that makes up the 1st gallery 
</div> 
<div id="gallery2" class="gallery" style="display:none"> 
    A whole lot of html that makes up the 2nd gallery 
</div> 
<div id="gallery3" class="gallery" style="display:none"> 
    A whole lot of html that makes up the 3nd gallery 
</div> 

<a href="JavaScript:void(0)" data-gallery="gallery1">Show gallery 1</a> 
<a href="JavaScript:void(0)" data-gallery="gallery2">Show gallery 2</a> 
<a href="JavaScript:void(0)" data-gallery="gallery3">Show gallery 3</a> 

​ 
$('a').click(function() { 
    $('.gallery').hide(); 
    $('#' + $(this).data('gallery')).show(); 
}); 

這裏有一個js小提琴:http://jsfiddle.net/nV5vy/

+0

我想要在不同鏈接的頁面上在wordpress中顯示不同的畫廊。我不想爲他們每個人編碼不同的html。 – Reis 2012-04-19 21:55:45

+0

啊我現在明白了這個問題,讓我看看 – koenpeters 2012-04-19 21:57:37

+0

你能把它放在http://jsfiddle.net/上嗎? – Reis 2012-04-19 22:00:16

相關問題