本文介绍了工作的jQuery Shadowbox表单示例是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

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

在onload函数中,我稍后调用Shadowbox.open()。当然,我正在通过选项。无论如何,我的表单提交整个页面,而不是返回false。



我一直在寻找一个实际的工作示例,如何处理表单的表单提交已交给Shadowbox。如果您能指出我的意见,那就太棒了。



谢谢

解决方案

你必须做的是:


  1. 使用iframe-player(当下载shadowbox时,你必须检查External sites和页面-checkbox)
  2. 为onFinish提供一个回调函数,确保iframe在提交表单前存在

  3. 更改表单的目标属性为 sb-player (这是由shadowbox创建的iframe的名称)

-code(将在shadowbox中运行谷歌搜索)

 < script type =text / javascript> 
Shadowbox.init();
$ b $(函数()
{
$('form')
.submit(function()
{
//引用需要在onFinish
var me = this;

Shadowbox.open({
//我们不需要加载页面
content:'about :blank',
//使用iframe-player
播放器:'iframe',
height:350,
width:850,
options:{
//发送没有
的表单//触发提交事件
// iframe可用时
onFinish:function()
{me.submit();}
}
});
//将iframe(名称是sb-player)设置为表单$ b $(this).attr('target','sb-player')的目标。

返回false;
});
});

< / script>
< form action =http://google.de/search>
< input name =qvalue =shadowbox>
< input type =submit>
< / form>


I have

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

Inside of the onload function, I later call Shadowbox.open(). Of course, I am passing options. Anyway, my form submits the entire page and fails to return false instead.

I have been looking for an actual working example of how to handle form submissions for a form that has been handed to Shadowbox. If you can point me to one, that would be amazing.

Thank you

解决方案

What you have to do is:

  1. use the iframe-player(when downloading shadowbox you must check the "External sites and pages"-checkbox)
  2. provide a callback-function for onFinish, to be sure that the iframe exists before really submitting the form
  3. change the form's target-attribute to sb-player(that's the name of the iframe created by shadowbox)

Example-code(will run a google-search in a shadowbox)

<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>

这篇关于工作的jQuery Shadowbox表单示例是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:44