最后加载特定的 div
我正在尝试制作一个页面,其中某个 div(包含大量 php、html 和 javascript 内容)在页面的其余部分之后加载。如果可以的话,这可能吗?
I'm trying to make a page where a certain div (with lots of php, html and javascript content) loads after the rest of the page. Is this possible if so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将此 div 应用于隐藏样式,然后使用 javascript 来显示它:
但是如果您想避免最初加载它,您可以使用 AJAX:
另请注意,如果您希望在加载所有其他内容(包括图形)后进行此加载,您可以使用
$(window).load
而不是$(document).ready
:You could apply this div a hidden style and then use javascript to show it:
But if you want to avoid loading it initially you could use AJAX:
Also note that if you want this loading to happen once all other content is loaded including graphics you could use the
$(window).load
instead of$(document).ready
:我有一个类似的问题,需要在创建某个 div 后填写数据。
我对此堆栈使用 .ejs 文件。
我所做的就是将所有代码拉到 .ejs 页面并按照我需要的方式对其进行排序。
例如。
I had a similar Issue, needed the data to be filled in after a certain div was created.
I use .ejs files for this stack.
What I did was Pull all the code to the .ejs page Ordering it in the way I needed.
For Ex.
查看 jQuery 的 $.ajax 和相关函数。我想您会发现它们正是您正在寻找的东西。一个简单的例子:
look in to jQuery's $.ajax, and related functions. I think you'll find they're exactly what you're looking for. a simple example:
一定
要有
css中
。然后
The certain
must have
in css.
An then
有几种方法可以做到这一点。其一,您可以将该 div 放在页面的末尾,并在其前面使用 Flux() ;但这不是很可靠,而且很难获得正确的位置和喜好。更好的方法是 ajax:
这只会在页面加载后执行,然后将内容加载到 div 中。当然,它假设 myurl.php 仅输出应该位于所述 div 中的内容。
假设你有这个页面:
myurl.php 输出这个:
这将导致:
There are several ways to do this. For one, you could put that div at the end of the page and flush() just before it; but this isn't very reliable, and it's pretty darned hard to get position and the likes right. A better way would be ajax:
this will only execute after page load and then load the contents into the div. It of course assumes myurl.php outputs only content that should be in said div.
So say you have this page:
And myurl.php outputs this:
which would result in: