保持元素存活?浏览网站时?
我不知道如何问这个问题,但我希望有人能帮助我。例如,在浏览网站时是否可以将某个元素(即:页脚或某种元素)保留在查看器页面中?即使用户更改页面(或单击链接),页脚也不会消失吗?
我希望我的问题很清楚?
谢谢!
I'm not sure how to ask this, but I hope someone can help me out. Is it possible to have, say, an element (ie: footer or some sort) stay in the viewer page while browsing the site? Not have the footer go away even if the user change pages (or clicks on a link)?
I hope my question is clear?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实现此目的的方法是,当有人单击您网站上的链接时,通过 AJAX/jQuery 加载所有内容。
您正在寻找的东西如下:
链接页面只需要其中包含核心信息,并且将自动给出来自登陆页面的任何CSS信息。但是,页面上的菜单和 mainContent div 标记之外的任何内容都是静态的。
The way this can be achieved is by making all content loaded through AJAX/jQuery when someone clicks a link around your website.
Something you are looking for is as follows:
The linking pages only need to have the core information in them, and will be automatically given any css information from the landing page. However you will have the menu and anything outside the mainContent div tag static on the page.
您可以使用 iframe 来显示您的网站,并将页脚保留在实际文件中。不过这也有它的缺点,所以我不推荐它。
您还可以使用 AJAX 来加载页面,这是一种更合乎逻辑的方法。
You could use an iframe to display your site, and have the footer remain in the actual file. This has its disadvantages though, so I don't recommend it.
You could also use AJAX to load your pages, which is a more logical approach.
正如乔提到的,框架是一种选择,但现在人们不赞成使用框架。
另一种选择是使用 AJAX。这比框架更复杂,但会带来更好的体验。基本上,您要做的就是加载初始页面,这也会加载一些 JavaScript。 JavaScript 将附加到任何链接。当点击链接时,JavaScript 会将新页面加载到当前页面中,而不是像普通链接那样转到新页面并刷新整个页面。将加载的另一个页面将只是部分 HTML 页面,即不包括 html、head、body 标签和菜单等。相反,它只会包含内容。
下面是使用 jQuery 执行此操作的一些基本 JavaScript:
另一种选择是加载隐藏 div 中其他页面的所有内容。如果您有很多内容,这可能会导致非常大的初始负载。在这种情况下,您的 HTML 中将包含类似以下内容:
希望这会有所帮助。
As Joe mentioned, frames are an option, but they're frowned upon these days.
Another option is to use AJAX. This is a more complicated than frames, but results in a much better experience. Basically, what you'd do is have the initial page load, which would also load some JavaScript. The JavaScript would be attached to any link. When the link is clicked, instead of, like a normal link, going to a new page and the whole page refreshing, JavaScript would load the new page into the current page. The other page that would be loaded would only be a partial HTML page, ie, not including the html, head, body tags and the menu etc. Instead it would just have the content.
Here's some basic JavaScript using jQuery to do this:
Another option is to load all the content for the other pages in hidden divs. If you have a lot of content, this can result in a very large initial load. In this case you'd have something like this in your HTML:
Hopefully this helps.
唯一真正的方法是使用 ajax 加载页面。因此,您将拥有一个大 div,其中包含除页脚之外的所有内容。然后,当有人单击您的大 div 内的链接时,它将抓取链接的页面,并使用新页面刷新大 div。其他答案都比较详细,这只是一个非常简单的解释。我会开始研究 Ajax。
The only real way to do this, is to load the pages with ajax. So you're gonna have a big div that will contain everything inside of it, except for the footer. Then when someone clicks on a link inside of your big div, it will grab the linked page, and refresh the big div with the new page. The other answers are more detailed, this is just a very simplistic explanation. I would start looking into Ajax.
我认为您正在寻找 HTML 框架。互联网上有大量资源。这是一个,http://www.w3schools.com/html/html_frames.asp。
I think you're looking for HTML Frames. There are plenty of resources on the internet. Here's one, http://www.w3schools.com/html/html_frames.asp.