简体   繁体   English

使用多个HTML页面或使用javascript显示/隐藏div

[英]Use multiple html pages or show/hide divs with javascript

First of all, I have a background in C (++), Java, MATLAB and Python, mainly used for scientific and electronic applications (Math operation on data, reading data from sensors, microcontrollers). 首先,我有C(++),Java,MATLAB和Python的背景知识,主要用于科学和电子应用程序(对数据进行数学运算,从传感器,微控制器读取数据)。 But i'm relatively new to both HTML (CSS) and Javascript. 但是我对HTML(CSS)和Javascript还是比较陌生。 For both I've read some books. 我俩都读了一些书。 In HTML books, multiple pages are done by links (<a></a>) . 在HTML书籍中,多个页面是通过链接(<a></a>)

In javascript (which feels a lot more natural to me than HTML), I've seen some examples where there is only 1 html page, full of divs, who are shown and hiden each time a certain page needs to be shown. 在javascript中(我觉得比HTML更自然),我看到了一些示例,其中只有1个html页面,充满了div,每次需要显示特定页面时都会显示和隐藏它们。 This is done with the Jquery command $('#div1').hide() and $('#div2').show(); 这是通过Jquery命令$('#div1').hide()$('#div2').show();

Now my question is, what is the best practice? 现在我的问题是,最佳实践是什么? When is it better to have multiple HTML pages, and when is it better to have just hide/show divs with Javascript? 什么时候有多个HTML页面更好,什么时候只用Java隐藏/显示div更好?

Thanks 谢谢

Not Every one Can Use Javascript. 并非每个人都可以使用Javascript。 Not Every Computer Or Browser Has The Basics Of Java Installed. 并非每台计算机或浏览器都安装了Java基础。 But Every Computer Can Read HTML every Browswer Can Read HTML. 但是每台计算机都可以读取HTML,每个浏览器都可以读取HTML。 To identify If a visitor is using java. 识别访客是否正在使用java。

How to check whether Java plugins are installed or not in a browser using Code .? 如何使用Code检查浏览器中是否安装了Java插件?

Java is mostly installed now days with the browser some basic functions. 现在,大多数Java随浏览器提供了一些基本功能。 But older navigator or IE browsers dont always have it installed by default. 但是默认情况下,较旧的导航器或IE浏览器并不总是安装有它。

More Info Here also 更多信息在这里

How can I detect the Java runtime installed on a client from an ASP .NET website? 如何从ASP .NET网站检测客户端上安装的Java运行时?

The easiest is using <ul><li> css navigation themes. 最简单的方法是使用<ul><li> CSS导航主题。 Check this site out for more info. 请访问此网站以获取更多信息。

https://medialoot.com/blog/how-to-create-a-responsive-navigation-menu-using-only-css/ https://medialoot.com/blog/how-to-create-a-responsive-navigation-menu-using-only-css/

When you have multiple html pages and user clicks on links, then on each click a new web page has to be fetched from server and then rendered. 当您有多个html页面并且用户单击链接时,则每次单击都必须从服务器中获取一个新的网页,然后进行渲染。

Whereas when you do it in java script the same web page will be altered, so there are no additional requests to the server. 而当您使用Java脚本执行此操作时,相同的网页将被更改,因此不会向服务器发送其他请求。 And this will be much faster than loading a new web page. 这将比加载新网页快得多。

But remember the initial loading time is second approach is longer but its negligible. 但是请记住,初始加载时间是第二种方法虽然更长,但可以忽略不计。

Let me point out that there is no "best practice" to the question that you are asking. 让我指出,您所提出的问题没有“最佳实践”。 It is entirely up to the team if they want to push all the content in one page or keep them separately. 如果团队希望将所有内容推送到一页或单独保存,则完全取决于团队。

If in case you have a content that requires decent amount of images to be loaded, or contents that you are sure will rarely be seen, you might want to keep them in separate pages so as to make the page load faster. 如果您的内容需要加载相当数量的图像,或者您确定很少会看到这些内容,则可能需要将它们保留在单独的页面中,以使页面加载更快。

If you have heavy contents which requires a lot of interaction with javascript/jQuery then you certainly might want to keep them in separate pages so that later when you want to debug/add to the code it can be easily done. 如果您的内容繁重,需要与javascript / jQuery进行大量交互,那么您当然可以将它们保存在单独的页面中,以便以后在调试/添加到代码中时可以轻松完成。

The vice versa of the above holds true as well. 反之亦然。 If in case you just have small content, or simple text content then you can easily do it in a single page. 如果您只拥有少量内容或简单文本内容,则可以在单个页面中轻松完成。

Maybe you should use a tab component ? 也许您应该使用选项卡组件? bootstrap wraps one very nicely: 引导程序很好地包装了一个:

http://getbootstrap.com/javascript/ http://getbootstrap.com/javascript/

Maybe thats the best approach, also take a look at angular.js routes in specific, it should do what ever you are looking for. 也许那是最好的方法,还要具体看看angular.js路由,它应该可以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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