厚盒帮助在关闭时从父级 html 调用方法
我使用thickbox来加载html。这个 html 有一个表单,我需要将一些内容添加到数据库中。我在主 html 中有一个选择框(我从中加载厚盒的那个)。 我想要做的是,当我按下厚盒中的关闭按钮时,选择框必须使用我刚刚添加到数据库中的内容进行更新。我正在考虑修改厚盒关闭方法并调用更新选择框的方法,但是当我这样做时厚盒崩溃了。任何提示将不胜感激。
I use thickbox to load an html. This html has a form that i need to add some stuff to the database. I have a select box in the main html (the one that i load thickbox from).
What i want to do is when i press the close button in thickbox, the select box has to be updated with the stuff i just added in the database. I was thinking to modify the thickbox close method and to call my method that updates the select box but thickbox crashes when i do that. Any hint would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以“劫持”整个 tb_remove 函数。
这意味着您不仅会捕获链接点击,还会捕获 ESC 键按下。
这涉及到内联重命名原始删除方法并用您自己的方法替换它。
注意:请确保在首次调用 Thickbox 之前执行此操作,以获得最大成功。
you can also 'hijack' the whole tb_remove function.
this means that you will not only capture the link click but also the ESC key press..
this involves renaming the original remove method inline and substituting it with your own.
Note: make sure you do this before thickbox is first called for maximum success.
如果您使用 Firebug 检查正在运行的厚盒,您可以看到厚盒模式实际上是主页内的一个 div。您可以从厚盒中调用主页中的任何功能。
例如,此代码将“劫持”thickbox 关闭链接并执行额外的操作:
除了劫持thickbox 关闭链接之外,您还可以将代码放入thickbox 内的任何链接中。只需确保在自定义代码之前或之后调用 tb_remove() 来关闭厚盒窗口即可。如果涉及到提交表单,请使用jQuery表单插件通过AJAX提交表单,然后在成功提交表单后运行关闭函数。
关于更新选择框,请参阅我的答案 此处了解如何使其在每个浏览器中运行。
为了确保您的函数始终被调用,您可以将厚盒设置为使用
modal
模式,该模式将禁用转义键。记得输入关闭代码,因为默认情况下,厚框栏不会显示。If you inspect the thickbox in action using Firebug, you can see that the thickbox modal is actually a div inside the main page. You can just call any function in the main page from the thickbox.
For example, this code will 'hijack' the thickbox close link and do extra stuffs:
Beside hijack the thickbox close link, you can also put the code into any link inside the thickbox. Just make sure you call
tb_remove()
to close the thickbox window, before or after your custom code. If it involve submitting a form, use jQuery form plugins to submit the form via AJAX, and then run your close function on a successful form submit.About updating the select box, see my answer here about how to do make it run in every browser.
To make sure that your function always called, you can set the thickbox to use
modal
mode that will disable the escape key. Remember to put the close code, because by default, the thickbox bar will not displayed.