简体   繁体   English

如何预加载Javascript / JQuery / HTML对话框

[英]How To Pre-Load Javascript/JQuery/HTML Dialog Boxes

I have a lot of experience in Swing and WPF but not much in Javascript. 我在Swing和WPF方面有很多经验但在Javascript方面并不多。 I am learning as I go. 我正在学习。 The below is what I would like to do 以下是我想做的事情

  • Have a single HTML Page for End User 为最终用户提供一个HTML页面
  • Preload Dialogs which will be displayed in response to user action 预加载对话框,将显示以响应用户操作

Currently I have all the divs for the dialog boxes load as part of the document and then in the document $(document).ready() function I call hide() . 目前我将对话框的所有div作为文档的一部分加载,然后在文档$(document).ready()函数中调用hide()

I then open and close them. 然后我打开并关闭它们。 All this works currently. 这一切目前都有效。 However I have the following problems: 但是我有以下问题:

  • The divs sometimes momentarily appear on page load div有时会暂时出现在页面加载上
  • It annoys me that all these dialogs that are not part of the index page have to be loaded as part of the index page. 令我很生气的是,所有这些不属于索引页面的对话框都必须作为索引页面的一部分加载。 (I am a little OCD with Code Organization). (我是代码组织的小强奸)。

Thanks-in-advance, 提前致谢,

Guido 圭多

The jQueryUI Dialog will ease your display issues. jQueryUI对话框将缓解您的显示问题。 I've found it to be more stable than anything I could write myself. 我发现它比我自己写的任何东西都更稳定。 You can, using AJAX, load content dynamically and put that markup into a single dialog DIV. 您可以使用AJAX动态加载内容并将该标记放入单个对话框DIV中。 It's as simple as knowing the DIV's ID, setting the html based on the AJAX response and then calling .dialog() on the popup. 它就像知道DIV的ID一样简单,根据AJAX响应设置html,然后在弹出窗口中调用.dialog()。

You could start the dialog box divs off with a style attribute set to: 您可以使用设置为的样式属性启动对话框dival off:

style="display:none;"

Which is what jQuery does when it calls .hide(), then you wont have to wait for jquery to be ready before the element is hidden, the CSS will automatically do it for you 这是jQuery在调用.hide()时所做的事情,然后你就不必等待jquery在隐藏元素之前做好准备,CSS会自动为你做

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

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