Javascript 创建一个动态的单页 Web 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3655823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a dynamic one page web application
提问by BoilerBam
I would like to make a web application (PHP) that will have overlay container that contain dynamic fields/forms.
我想制作一个包含动态字段/表单的覆盖容器的 Web 应用程序 (PHP)。
I would like the user to complete the form but not be taken away from the main part of the page.
我希望用户完成表单但不会离开页面的主要部分。
Imagine, browsing a website and reporting a page error into an overlay but not being taken away from the page you were reading.
想象一下,浏览网站并将页面错误报告到叠加层中,但并未从您正在阅读的页面中删除。
Also, is it possible to make the form multiple parts/pages, such as user clicks next button and the next part of the form is presented?
另外,是否可以将表单分为多个部分/页面,例如用户单击下一步按钮并显示表单的下一部分?
采纳答案by Chris Fulstow
Nice example of this type of web app here, with some useful tips:
这种类型的网络应用程序的好例子在这里,有一些有用的提示:
回答by Iznogood
What you are looking for is called ajax.
您正在寻找的是ajax。
Using jQueryyou could easily create the kind of form you want where the whole page is notreloaded upon submission.
使用jQuery,您可以轻松创建所需的表单类型,在提交时不会重新加载整个页面。
Going into more details, check out jQuery UI. There a set of usually very simple to implement power tools to help create a dynamic webpage.
要了解更多详细信息,请查看jQuery UI。有一组通常很容易实现的强大工具来帮助创建动态网页。
So jQuery UI stuff for layout (look at tabs) and ajax through jQuery for your communication with the server (PHP).
因此,用于布局的 jQuery UI 内容(查看选项卡)和 ajax 通过 jQuery 用于您与服务器 (PHP) 的通信。
回答by omar-ali
I just finished building a single-page application using the Yii Framework for PHP and Jquery (Jquery UI as well).
我刚刚使用 Yii Framework for PHP 和 Jquery(还有 Jquery UI)构建了一个单页应用程序。
What I have learned is that Jquery isn't adequate enough to handle a true single-page application.
我了解到的是,Jquery 不足以处理真正的单页应用程序。
What you need to use is a library that handles a lot of issues that will come up whilst building SPA's and frees you from having to do a lot of DOM based manipulations.
您需要使用的是一个库,它可以处理构建 SPA 时出现的许多问题,并使您不必进行大量基于 DOM 的操作。
Instead what you'd end up doing is actually write a true application and let the 'library' handle those aspects for you.
相反,您最终要做的实际上是编写一个真正的应用程序,并让“库”为您处理这些方面。
One library that comes to mind is AngularJS.
我想到的一个库是 AngularJS。
Hope this helps.
希望这可以帮助。

