jQuery 淡出由 php 而不是 Javascript 显示的 div?
看起来这可能很容易,但是从阅读其他SO答案来看,有很多方法可以让它工作:
我下面有一个“谢谢”div,它显示了 php 表单何时成功提交:
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks"></div>
页面在表格已提交;表单的 php 包含在页眉中,上面的 php 位于 中,提交表单时,会出现“thanks”div。
问题:div 如何在几秒钟后淡出(或简单地删除)?
文档就绪似乎不起作用,因为页面未重新加载。 jQuery 可以检测 div 的出现然后启动淡出计时器吗?
如果可能的话,我想继续使用 php 表单,而不是转向 jQuery 表单。
Seems like this might be easy, but from reading other SO answers there are a number of ways for it to possibly work:
I have the "thanks" div below that shows when a php form is sucessfully submitted:
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks"></div>
The page does not reload after the form is submitted; the php for the form is included in the page header, the php above is in <body>
, and when the form is submitted, the "thanks" div appears.
Question: How can the div be faded out (or simply removed) after a few seconds?
Document ready doesn't seem like it would work because the page is not reloaded. Can jQuery detect the appearance of the div and then start the fadeout timer?
If possible, I'd like to stay with the php form and not move to a jQuery form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您提交表单并且不是通过 ajax,那么您的页面正在重新加载,在这种情况下您可以执行以下操作:
这将等待 5 秒,然后淡出该元素,就像它得到的一样简单:) 如果没有' t 找到 div 与
$(".thanks")
那么没问题,它只是没有任何动画...这意味着您可以将其粘贴在外部脚本中,没有任何问题。If you're submitting the form and it's not via ajax, then your page is reloading, in which case you can do this:
This would wait 5 seconds then fade out the element, about as simple as it gets :) If it doesn't find the div with
$(".thanks")
then no problem, it just won't have anything to animate...meaning you can stick this in an external script without any issues.由于页面已经加载,您可以在 ajax 响应中打印淡出脚本:
Since the page is already loaded, you can print the fade out script in your ajax response:
不能直接将div设置为display:none吗?然后使其在表单提交代码中可见。
Can't you just set the div to display:none? Then make it visible in the form submit code.