如何使用 SimpleModal 获取回调

发布于 2024-08-11 17:33:41 字数 477 浏览 1 评论 0 原文

我无法从 simplemodal 中捕获 onclose 。如果可以的话请帮我一下,因为我是 jQuery 的新手...

<a href="http://url/" onclick="$(this).modal({width:833, height:453}).open(); return false;">

可以工作,但我想在模式对话框关闭时调用 javascript 函数。我如何附加,例如 updateTable();到关闭事件?

我试过

以及它的所有 Stud 变体,但老实说,查看示例页面中的嵌套函数只会让我头晕(第二个示例也有 href,但它不允许我将其发布在这里)......

I've been unable to catch the onclose from within simplemodal. please give me a hand if you can as i'm new to jQuery...

<a href="http://url/" onclick="$(this).modal({width:833, height:453}).open(); return false;">

works, but i would like to call a javascript function whenever the modal dialog is closed. How do i attach, say updateTable(); onto the close event??

I've tried

<a href="" onclick="$(this).modal({onClose: alert(1);$.modal.close();}).open();"

and all stupd variations of this, but honestly looking at the nested functions in the example page only made me dizzy (the second example also has the href, but it doesnt let me post it here)....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

掌心的温暖 2024-08-18 17:33:41

如果我理解正确,您想要

HTML:

<a href="http://www.google.com" id="clicker">Click me!</a>

JavaScript

var c = function closer() {
    $.modal.close();
    alert("Done!"); 
}
$(document).ready(function() {
    $("#clicker").click(function() {
        $.modal(
            '<iframe src="'+this.href+'" width="833" height="453">asd</iframe>',
            {onClose:c}
        );
        return false;
    });
});

检查 http:// jsbin.com/ofimi 获取工作示例

If I understand you correctly you want to

  • Click on a link (e.g. with id clicker)
  • The page defined by the URL in the href of this <a href="..."> tag should be the modals content
  • When the user closes the modal you want to trigger some action and close the modal

HTML:

<a href="http://www.google.com" id="clicker">Click me!</a>

JavaScript

var c = function closer() {
    $.modal.close();
    alert("Done!"); 
}
$(document).ready(function() {
    $("#clicker").click(function() {
        $.modal(
            '<iframe src="'+this.href+'" width="833" height="453">asd</iframe>',
            {onClose:c}
        );
        return false;
    });
});

Check http://jsbin.com/ofimi for a working sample

两相知 2024-08-18 17:33:41

首先,使用 jQuery 时不必添加 onclick 属性。
假设

 <a id="clicker" href="http://url/" >Click</a>

然后

  $(document).ready(function(){
      $("#clicker").click(function(){
          $(this).modal({width:833, height:453, onClose: function(){ 
             //your code here}})
          .open(); 
          return false;
      });

 });

$(this) 引用实际上指的是 a 标签,也许您可​​能想要使用一个名为dialog 的 div,如下所示:

 <div id="dialog"></div>

并将 jQuery 更改为

$("#dialog").modal(...)

UPDATE: 根据您的评论。试试这个。

   <head>
      <!-- Include your script tags here to load the jQuery and simplemodal scripts -->
      <script type="text/javascript">
          $(document).ready(function(){
              $("#clicker").click(function(){
                 $("#dialog").modal({onClose: function(){ 
                  alert("Closing");
                 }
                 });
                return false;
              });
          });


      </script>

      </head>
      <body>
           <div id="dialog"></div>
           <a href="#" id="clicker">Click</a>
      </body>

First you do not have to add the onclick attribute when using jQuery.
Assume

 <a id="clicker" href="http://url/" >Click</a>

Then

  $(document).ready(function(){
      $("#clicker").click(function(){
          $(this).modal({width:833, height:453, onClose: function(){ 
             //your code here}})
          .open(); 
          return false;
      });

 });

The $(this) reference actually refers to the a tag, maybe you might want to use a div called dialog like this:

 <div id="dialog"></div>

and change the jQuery to

$("#dialog").modal(...)

UPDATE: Based on your comment. try this.

   <head>
      <!-- Include your script tags here to load the jQuery and simplemodal scripts -->
      <script type="text/javascript">
          $(document).ready(function(){
              $("#clicker").click(function(){
                 $("#dialog").modal({onClose: function(){ 
                  alert("Closing");
                 }
                 });
                return false;
              });
          });


      </script>

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