jquery:Colorbox 关闭 iFrame onsubmit

发布于 2024-12-07 15:44:10 字数 598 浏览 1 评论 0原文

我有一个关于提交后关闭带有颜色框的表单的问题。我发现了这个问题,所以我现在知道如何在提交后关闭表单。问题是另一个 javascript 验证我表单的输入字段,当某些字段未填写时,将会出现一条错误消息(一个简单的alert())...我想仅在验证返回 no 时关闭 clorbox iframe onsubmit错误..否则用户会得到提示,他错过了一些输入字段,但表单无论如何都会关闭...所以我如何使用 jQuery 检查这一点..是否有可能检查“alert()”是否为显示于屏幕...然后可以说,当显示警报弹出窗口时,不要关闭颜色框窗口,否则关闭它,因为没有错误...有人明白我的意思吗?再次强调:我无法更改验证脚本!然后我可以简单地在这个脚本中添加 .colorbox.close(); ...

验证是一个简单的函数,在提交时执行...有一个变量“msg”,其中包含错误消息在这个函数中......必须有一种方法可以在函数执行时获取这个“msg”变量并检查它是否为空......?

谁能帮我解决这个问题...这对我来说有点难以解释..

i´ve got a question about closing a form withing a colorbox after submit. I found this question so i now know how to close the form after submit. The problem is that another javascript validates the input fields of my form and there will be an error message (a simple alert()) when some fields are not filled in...i wanne close the clorbox iframe onsubmit only when the validation returns no error..otherwise the user will get the hint that he missed some input fields but the form will close anyway...so how can i check this with jQuery..is there a possiblity to maybe check if an "alert()" is shown on screen...then is could say, when the alertpopup is shown don´t close the colorbox window, otherwise close it because there was no error...does anyone understand what i mean? Again: I cannot change the validation script! Then i could simply add the .colorbox.close(); within this script...

The validation is a simple function which is executed onsubmit...there is a variable "msg" which contains the errormessage within this function..there must be a way to get this "msg" variable when the function executes and to check whether it´s empty or not....?

Can anyone help me with this...it´s a bit difficult to explain for me..

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

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

发布评论

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

评论(1

季末如歌 2024-12-14 15:44:10

您可以通过以下方式引用 iFramed 内容来获取“msg”元素的内容:

parent.msg-field-name

在类似的情况下我所做的是这样的:

  • 为用户留下取消iFrame表单的方法。此退出路径在提交时使用 ColorBox 的“内置”关闭方法
  • ,测试错误验证。如果通过,则使用允许内置关闭方法成功,如果没有,则不要离开表单。

您可以从插件作者的网站中找到具体操作方法:

阻止 ColorBox 关闭/更改 $.colorbox.close() 的行为

close 方法 ($.colorbox.close()) 可以缓存并重新定义,以便对 ColorBox 关闭时发生的情况提供一些控制。这会影响绑定到它的控件(例如 escKey、overlayClose 和关闭按钮)并直接调用 close 方法。

例如,假设我们打开 ColorBox 来显示包含表单的 html 片段,并且我们想警告访问者,如果他们在提交数据之前尝试关闭 ColorBox,他们将丢弃表单。

var originalClose = $.colorbox.close; 
$.colorbox.close = function(){ 
    var response; 
    if($('#cboxLoadedContent').find('form').length > 0){ 
       response = confirm('Do you want to close this window?'); 
       if(!response){ 
          return; // Do nothing. 
       } 
    } 
    originalClose(); 
}; 
$('a#example').colorbox();

You can probably get the contents of the "msg" element from the iFramed content by referring to it this way:

parent.msg-field-name

What I have done in a similar situation is this:

  • Leave a way for the user to cancel the iFrame form. This exit path uses ColorBox's "built-in" close methods
  • on Submit, test for error validation. If it passes, use allow the built-in close method to succeed, if it doesn't then don't leave the form.

You can find out exactly how to do form the plugin author's website:

Prevent ColorBox from closing / Change the behavior of $.colorbox.close()

The close method ($.colorbox.close()) can be cached and redefined as to offer some control over what happens when ColorBox is closed. This affects controls that are bind to it (such as the escKey, overlayClose, and the close button) and calling the close method directly.

For example, lets say we open ColorBox to display an html snippet containing a form, and we want to warn the visitor that they are discarding their form if they try to close ColorBox before they submit their data.

var originalClose = $.colorbox.close; 
$.colorbox.close = function(){ 
    var response; 
    if($('#cboxLoadedContent').find('form').length > 0){ 
       response = confirm('Do you want to close this window?'); 
       if(!response){ 
          return; // Do nothing. 
       } 
    } 
    originalClose(); 
}; 
$('a#example').colorbox();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文