简体   繁体   English

使用jQuery隐藏/显示内容

[英]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: 优点:

  • Front-end access to all content immediately 前端立即访问所有内容

Cons: 缺点:

  • Long page load which might result in 404 or slow connection 长页面加载可能会导致404或连接缓慢
  • Dependent on user device. 取决于用户设备。 If user doesn't have a current browser then your page might break. 如果用户没有当前的浏览器,则您的页面可能会中断。
  • Client might not have JavaScript enabled, breaking your website completely 客户端可能未启用JavaScript,从而完全破坏了您的网站
  • If there is a lot of data, then the user device might not be able to handle it. 如果有大量数据,则用户设备可能无法处理它。 JavaScript can be quite taxing on older devices. 在较旧的设备上,JavaScript可能会非常繁重。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM