为了得到你需要拉这个数据从数据库或其它网站或使用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