厚盒帮助在关闭时从父级 html 调用方法

发布于 2024-08-21 21:49:44 字数 182 浏览 7 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷迭香的记忆 2024-08-28 21:49:45

您还可以“劫持”整个 tb_remove 函数。
这意味着您不仅会捕获链接点击,还会捕获 ESC 键按下。

这涉及到内联重命名原始删除方法并用您自己的方法替换它。

    <script type="text/javascript">
        var original_tb_remove = tb_remove;
        tb_remove = function () { 
                  **** insert your coolness here ****
                  original_tb_remove(); 
                  return false; } 
    </script>

注意:请确保在首次调用 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.

    <script type="text/javascript">
        var original_tb_remove = tb_remove;
        tb_remove = function () { 
                  **** insert your coolness here ****
                  original_tb_remove(); 
                  return false; } 
    </script>

Note: make sure you do this before thickbox is first called for maximum success.

冰火雁神 2024-08-28 21:49:45

如果您使用 Firebug 检查正在运行的厚盒,您可以看到厚盒模式实际上是主页内的一个 div。您可以从厚盒中调用主页中的任何功能。

例如,此代码将“劫持”thickbox 关闭链接并执行额外的操作:

$("#TB_closeWindowButton").click(function(){
  tb_remove();
  //do extra stuffs, such as get a new select
  var select_parent = $('#theselect').parent();
  $.get('new_select.php',
        {},
        function(data){
          select_parent.html(data);
        });
});

除了劫持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:

$("#TB_closeWindowButton").click(function(){
  tb_remove();
  //do extra stuffs, such as get a new select
  var select_parent = $('#theselect').parent();
  $.get('new_select.php',
        {},
        function(data){
          select_parent.html(data);
        });
});

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文