jQuery.validate 可能破坏了 Facebox 弹出窗口

发布于 2024-09-26 09:44:19 字数 1538 浏览 7 评论 0原文

我的 Facebox 弹出窗口包含一个带有提交按钮的表单。我还有第二个按钮来打开一个不相关的 Facebox 弹出窗口,该弹出窗口在我将 jQuery.validate 添加到项目之前正在运行。我需要在提交之前验证电子邮件和密码字段。

我应该补充一点,这些弹出窗口是通过外部 .html 文件加载的。这通过 AJAX 请求加载它们。

index.html 上,设置弹出窗口($k 等于 jQuery.noConflict());

$k('a[rel*=example_2]').facebox_1({
    loading_image : '/images/loading.gif',
    close_image   : '/images/closelabel.gif'
});

点击链接打开上面的 Facebox:

<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>

下面的所有内容都在 login.html

验证:

$(function () {
    $('form[name="login"]').validate({
        rules: {
            email: { required: true, email: true },
            password: "required"
        },
        messages: {
            email: "",
            password: ""
        }
    });
});

以及表单:

<form name="login" method="post" action="login.aspx">

以及不起作用的按钮

<a href="#" title="Register" onclick="showRegister()" ><img src="images/register.jpg" /></a>

Nick 帮助我在 这篇文章,但它似乎破坏了另一个按钮。我在调试脚本时遇到问题,因为我不知道 Firebug 是否可以在外部请求(通过 XHR)页面中设置断点。

我尝试向刚刚调用 showRegister() 的损坏按钮添加一个单击处理程序,但这也不起作用。 showRegister() 简单调用 $('#linkFromIndexDotHtml').click();,它实际上是来自 index.html 的链接。我认为这可能是问题所在,但它之前就有效。

My Facebox pop-up contains a form with a submit button. I also have a second button to open an unrelated Facebox pop-up that was working before I added jQuery.validate to the project. I need to validate the email and password fields prior to being submitted.

I should add that these pop-ups are loaded via external .html files. This loaded them via AJAX request.

On index.html, the pop-ups are setup ($k is equal to jQuery.noConflict());

$k('a[rel*=example_2]').facebox_1({
    loading_image : '/images/loading.gif',
    close_image   : '/images/closelabel.gif'
});

And the link clicked to open the above Facebox:

<a href="login.html" title="Log In" rel="example_2" id='login'>Log In </a>

And everything below is in login.html

The validation:

$(function () {
    $('form[name="login"]').validate({
        rules: {
            email: { required: true, email: true },
            password: "required"
        },
        messages: {
            email: "",
            password: ""
        }
    });
});

And the form:

<form name="login" method="post" action="login.aspx">

And the button that doesn't work

<a href="#" title="Register" onclick="showRegister()" ><img src="images/register.jpg" /></a>

Nick helped me get the form posting in this post, but it seems to have broken the other button. I'm having problems debugging the script, because I don't know if Firebug can set breakpoints in externally requested (via XHR) pages.

I tried adding a click handler to the broken button that just called showRegister(), and that didn't work either. showRegister() simple calls $('#linkFromIndexDotHtml').click(); which is, in fact, a link from index.html. I thought that may be the problem, but it worked prior.

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

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

发布评论

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

评论(1

皓月长歌 2024-10-03 09:44:19

我遇到了同样的问题,并使用 http://old.nabble 的信息解决了它。 com/Validation-and-Facebox-td22187264s27240.html

$.extend($.facebox, {
    settings: {
    dom_data: null,
    dom: null,

...
*在主声明中添加变量 dom 和 dom_data
脸盒

if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox.settings.dom = target;
      $.facebox.settings.dom_data = $(target).children();
      $.facebox.reveal($(target).children().show(), klass)

...
*这

最后在 fillFaceboxFromHref 中,

$(document).bind('close.facebox', function() {
  if($.facebox.settings.dom){
  $($.facebox.settings.dom).append($.facebox.settings.dom_data);

  $.facebox.settings.dom = null;
  $.facebox.settings.dom_data = null;
  }

...
* 这是在文件的末尾

I had the same problem and solved it with info from http://old.nabble.com/Validation-and-Facebox-td22187264s27240.html

$.extend($.facebox, {
    settings: {
    dom_data: null,
    dom: null,

...
*add in the variables dom and dom_data in the main declaration of
facebox

if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox.settings.dom = target;
      $.facebox.settings.dom_data = $(target).children();
      $.facebox.reveal($(target).children().show(), klass)

...
*this is in fillFaceboxFromHref

finally,

$(document).bind('close.facebox', function() {
  if($.facebox.settings.dom){
  $($.facebox.settings.dom).append($.facebox.settings.dom_data);

  $.facebox.settings.dom = null;
  $.facebox.settings.dom_data = null;
  }

...
* this is at the end of the file

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