[英]Using jQuery to Hide/Show Content
I am having a website that basically shows information related to a business house. 我有一个基本上可以显示与营业所相关信息的网站。 I do not want to have a multi page website (for about us, contact us and other such pages), but I have a considerable amount of content to be shown. 我不想有一个多页的网站(关于我们,请与我们联系以及其他此类页面),但是我有很多内容需要显示。
And I would not prefer to load content again and again through consecutive fetches from the server through AJAX. 而且,我不希望通过AJAX从服务器连续获取一次又一次地加载内容。
So, can I have all my content loaded on the first load itself and have only the required content shown (visible) and hide and show the appropriate content using jQuery. 因此,我能否将所有内容加载到第一次加载本身上,并且仅显示(可见)所需的内容,并使用jQuery隐藏和显示适当的内容。 Is it a proper approach that can be adopted ? 是否可以采用适当的方法? What are its possible disadvantages ? 它可能有什么缺点?
What you are asking can be achieved with a Singlepage framework like: http://alvarotrigo.com/fullPage/ or AngularJS 您的要求可以通过单页框架实现,例如: http ://alvarotrigo.com/fullPage/或AngularJS
Pros: 优点:
Cons: 缺点:
EDIT 1 编辑1
My personal preference for Singlepage solutions is AngularJS, so if you are interested in this i would recommend this tutorial: 我个人对Singlepage解决方案的偏爱是AngularJS,因此,如果您对此感兴趣,我会推荐本教程:
scotch.io/tutorials/single-page-apps-with-angularjs-routing-and-templating scotch.io/tutorials/与angularjs路由和模板化的单页应用程序
<a href="#about-us" title="About Us">About Us</a>
<div id="about-us" class="content">Some content here</div>
<script>
$(document).ready(function(){
$('a').click(function(){
var link = $(this).attr('href');
$('.content').hide();
$(link).show();
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.