jQuery 对话框打开但不关闭!
我正在对一些 HTML 进行 Ajax GET,然后通过以下方式填充 div:
$(theDiv).html(theHtml)
此 HTML 包含一个按钮(假设为“按钮 A”),该按钮通过以下方式显示 jQuery 对话框:
$(selector).dialog({modal:true});
单击“按钮 A”时,该对话框会显示时间。但是,在对话框中,我添加了一个“取消”链接。取消链接触发:
$(selector).dialog("close")
我注意到大多数时候它都工作得很好。但是,如果我在 Ajax GET 完成后立即快速单击“按钮 A”,取消链接将不会关闭对话框!对话框右上角的“X”按钮始终有效,但“取消”按钮是我遇到的问题。
我尝试了许多不同的方法来使其发挥作用,但均无济于事。这种情况发生在 Firefox 3.5.9 和 IE 7 中。如果我使用 Firebug 并在 .dialog('close');
语句后放置一个断点,那么我会注意到屏幕从灰色变为白色,但对话框保持打开状态。我什至尝试通过这样做来强制解决这个问题:
$(selector).css("display", "none");
无济于事。
不管出于什么原因,第一次 Ajax GET 触发时,我从来没有遇到过这个问题......所以当我第一次访问页面并执行 GET 时,它每次都会起作用。但是,如果我留在页面上并在 DOM 仍加载时继续触发 GET,则它可能仅在 50% 的时间内有效。
我非常感谢任何人愿意提供的帮助!
谢谢,
安迪
I'm doing an Ajax GET for some HTML which then populates a div via:
$(theDiv).html(theHtml)
This HTML includes a button (let's say "Button A") that displays a jQuery dialog via:
$(selector).dialog({modal:true});
When "Button A" is clicked, the dialog shows up every time. However, inside the dialog, I've included a Cancel link. The cancel link fires:
$(selector).dialog("close")
I've noticed that most of the time it works just great. However, if I quickly click "Button A" immediately after the Ajax GET is finished, the cancel link will NOT close the dialog! The "X" button in the upper right of the dialog always works, but the Cancel button is the one I'm struggling with.
I've tried a number of different things to get this to work to no avail. This is happening in Firefox 3.5.9 as well as IE 7. If I use Firebug and put a breakpoint after the .dialog('close');
statement, then I notice that the background color on the screen changes from gray to white, but the dialog remains open. I've even tried forcing the issue by doing:
$(selector).css("display", "none");
to no avail.
For whatever reason, the first time that the Ajax GET fires, I NEVER have this problem... So when I visit the page and execute the GET the first time, it works every time. However, if I remain on the page and continue to fire the GET while the DOM is still loaded, it works maybe 50% of the time only.
I greatly appreciate any help anyone is willing to provide!
Thanks,
Andy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你点击“取消”按钮时,JavaScript 看起来确实还没有准备好。
您应该尝试在ajax加载页面的document.ready事件上弹出警报,如果您能够在警报出现之前单击取消按钮,那么javascript只是比您慢。
只需添加类似的内容:
It really look like that javascript isn't ready at the moment you click the "cancel" button.
You should try to make pop an alert on document.ready event of the ajax loaded page, if you're able to click your cancel button before the alert come, javascript is just slower than you.
Just add something like that :