用另一个div中的链接更改div内容 [英] Change div content with link in another div
问题描述
我有一个菜单栏,里头有链接。当你点击链接时,我想只更改主div中的内容。我正在考虑在PHP中做,但你将不得不重新加载页面。所以我需要在JavaScript中做到这一点,但我不知道JavaScript。
i have a menu bar with links which are in the header. when you click the link, i want to just change the content in the main div. i'm thinking of doing it in php, but you will have to reload the page. So i need to do it in javascript, but i dont know javascript.
这里是我在标题div中的菜单代码:
here is my menu code in the header div:
<ul id="nav">
<li><a href="#">Enter Information</a></li>
<li><a href="#">View Records</a></li>
<li><a href="#">View Upcoming</a></li>
</ul>
推荐答案
根据内容的类型,可供选择的选项。如果您需要在主内容中加载新页面,则可以使用 iframe 和一些内容JavaScript的。如果你需要加载简单的文本,你可以简单地使用javascript。
Depending on the type of content, you have a few options available to you. If you need to load a new page into the main content, you can use iframes and some javascript. If you need to load simple text, you can simply use javascript.
根据你的反馈,你会做这样的事情(注意 - 我是从髋关于语法,但这通常是你的代码需要看起来像):
Based on your feedback, you'll do something like this (note- I'm shooting from the hip regarding syntax, but this is generally what your code will need to look like):
<a href="#" onclick="UpdateIFrame('mypage.html')">Link 1</a>
<iframe id="MainContent">
</iframe>
<script>
function UpdateIFrame( newPageAddress ){
document.getElementById("MainContent").contentWindow.location = newPageAddress;
}
</script>
这篇关于用另一个div中的链接更改div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!