爲了得到你需要拉這個數據從數據庫或其它網站或使用AJAX另一個網頁的動態內容。我推薦閱讀和learning JQuery,因爲它非常簡單,像其他任何語言一樣,遵循邏輯流程。 JQuery的語法也很簡單,所以它不應該太難拾取。但我離題了。
如果你的HTML結構如下:
<div id="container">
<div id="panel1" class="panel">
<a href="#" class="button" id="btn-1">Button 1</a>
<div id="iframe-1"></div>
</div>
<div id="panel1" class="panel">
<a href="#" class="button" id="btn-2">Button 2</a>
<div id="iframe-2"></div>
</div>
<div id="panel1" class="panel">
<a href="#" class="button" id="btn-3">Button 3</a>
<div id="iframe-3"></div>
</div>
</div>
和你的CSS大致是這樣的:使用jQuery
.panel{
float:left;
}
/* Initially hide all iframe divs */
.panel > div{
display:none
}
/* Initially show only the first iframe div */
.panel > div:first-child{
display:block;
}
,你可以使用:
//Run the code after the elements of the page have been downloaded. This is usually how most JQuery syntax starts.
$(document).ready(function(){
//When the button is clicked, run a function
$('.button').click(function(e){
e.preventDefault(); //Prevents default click behavior; similar to defining onclick='return false;' in the <a /> tag.
$('.button').siblings('div').hide(); //Hide all open iframe divs
$(this).siblings('div').show(); //Show the iframe div corresponding to clicked link
var id = $(this).attr('id').replace('btn-','iframe-'); //Get the ID of the link clicked and replace 'btn-' with 'iframe-'
$('#'+id).load('http://<url of the page you want to load>'); //Load the new web page or content into the iframe div. This could be an absolute or relative path.
});
});
到類似.load()功能,也有.ajax()這個功能更多全面。另外請記住,Javascript的工作原理是它在客戶端計算機上編譯,並且在加載頁面時運行一次。因此,當獲取正被添加到頁面的HTML的動態數據時,需要爲新內容重新加載諸如點擊,懸停等任何動作。您需要使用JQuery的.on()或.delegate()事件。
希望這會有所幫助。
您是否有過設計/佈局或示例HTML?人們更可能幫助你完成整個事情。 – 2012-02-08 19:57:30
我的佈局是,我也一直在建設我的網站。我基本上有我想要的尺寸和東西,我只是不知道編碼風格或如何運行它。見上面編輯過的帖子。 – H4R73Y 2012-02-08 20:11:13
在jsfiddle.net上發佈示例並在此處發佈URL。 – 2012-02-08 20:14:28