0

我有

window.onload = function()
{
    $('form').submit(function()
    {
        return false;
    });
};

在 onload 函数内部,我稍后调用 Shadowbox.open()。当然,我正在传递选项。无论如何,我的表单提交了整个页面并且未能返回 false 。

我一直在寻找一个实际的工作示例,说明如何处理已提交给 Shadowbox 的表单的表单提交。如果你能给我指出一个,那将是惊人的。

谢谢

4

1 回答 1

1

你要做的是:

  1. 使用 iframe 播放器(下载 shadowbox 时,您必须选中“外部站点和页面”-复选框)
  2. 为 onFinish 提供一个回调函数,以确保 iframe 在真正提交表单之前存在
  3. 将表单的目标属性更改为sb-player(即 shadowbox 创建的 iframe 的名称)

示例代码(将在影子框中运行谷歌搜索)

<script type="text/javascript">
Shadowbox.init();

$(function() 
  {
    $('form')
      .submit(function()
              {
                //reference to the form, needed in onFinish
                var me=this;

                Shadowbox.open({
                                  //we dont need to load a page
                                content: 'about:blank',
                                  //use the iframe-player
                                player:  'iframe',
                                height:  350,
                                width:   850,
                                options: {
                                          //send the form without 
                                          //triggering the submit-event
                                          //when the iframe is available
                                          onFinish:function()
                                                   {me.submit();}
                                         }
        });
        //set the iframe(the name is sb-player) as target of the form
          $(this).attr('target','sb-player');

        return false;
    });
});

</script>
<form action="http://google.de/search">
<input name="q" value="shadowbox">
<input type="submit">
</form>
于 2011-07-13T02:34:36.613 回答