1

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

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

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

我试过了

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

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

4

2 回答 2

3

如果我理解正确你想

  • 点击一个链接(例如使用 id clicker)
  • 这个<a href="...">标签的href中的url定义的页面应该是modals内容
  • 当用户关闭模态时,您想要触发一些动作并关闭模态

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以获取工作示例

于 2009-11-18T01:34:50.430 回答
0

首先,使用 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(...)

更新:根据您的评论。试试这个。

   <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>
于 2009-11-17T22:31:43.900 回答