打开使用JavaScript和AJAX同一个页面中的链接 [英] Opening a link within the same page using javascript or ajax
问题描述
我有什么是我的左侧边栏和一个主内容区域右边的链接列表, 我希望能够对链接点击左边,并具有各自的页面中的内容区域开放,而不是重新加载新页。我敢肯定,这是很容易使用JavaScript和AJAX技术,我只是不知道如何。 在此先感谢您的帮助!
What I have is a list of links in my left sidebar and a main content area to the right, I want to be able to click the links to the left and have each "page" open in the content area, instead of reloading a new page. I'm sure this is fairly easy using javascript or ajax, I'm just not sure how. Thanks in advance for your help!
推荐答案
假设你有
<div id='content'></div>
右侧和连杆的左
on the right side and a link on the left
<a href='#' id='contact_link'>Contact</a>
您可以使用jQuery的加载函数加载DIV与页面的内容,当你点击链接:
You can use JQuery's load function to load the div with the content of a page when you click the link:
$("#contact_link").click(function() {
$("#content").load("contact.html");
});
如果你不使用JQuery的,你可以得到它此处,否则有如何做到这一点的纯JS。
If you're not using JQuery you can get it here, otherwise there are ways to do it in plain JS.
这篇关于打开使用JavaScript和AJAX同一个页面中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!