2011-09-07 113 views
1

我使用这个代码:jQuery .submit没有被触发?

$j("#register-form form").submit(function() { 
    if ($j("input:first").val() == "correct") { 
    $j("#registration-notification").animate({ 
      height: "21px", 
      opacity: 1, 
      'padding-top': "8px" 
     }, 800); 
    return true; 
    } 
    $j("span").text("Not valid!").show().fadeOut(1000); 
    return false; 
}); 

这种形式(从萤火虫代码):

<div id="register-form"> 
<form class="bbp-login-form" action="http://localhost/taiwantalkorgfinal2/wp-login.php" method="post"> 
<fieldset class="bbp-form"> 
<h5>Create a Taiwantalk account</h5> 
<div class="bbp-username"> 
<div class="bbp-email"> 
<div class="bbp-submit-wrapper"> 
</fieldset> 
</form> 

,使这个通知出现:

HTML:

<div id="registration-notification"> 
    <div id="message"> 
     <span><?php _e('Check your email for the username and password'); ?></span> 
     <a href="#" id="close-button">x</a> 
    </div> 
</div><!-- #container --> 

CSS:

#registration-notification { 
    background-color: #444; 
    color: #FFF; 
    height: 0; 
    opacity: 0; 
    padding: 0; 
    overflow: hidden; 
    #close-button { 
     background: #888; 
     color: #FFF; 
     float: right; 
     padding: 0 3px; 
     border-radius: 2px; 
     -moz-border-radius: 2px; 
     -webkit-border-radius: 2px; 
     behavior: url(PIE.htc); 
     &:hover { 
      background: #BA422B; 
      color: #FFF; 
     } 
    } 
    #message { 
     margin: 0 auto; 
     width: 940px; 
     span { 
      float: left; 
      width: 720px; 
     } 
     a { 
      color: #FFF; 
      font-weight: bold; 
     } 
    } 
} 
#header { 
    overflow: hidden; 
    padding: 9px 0 0; 
    h1 { 
     float: left; 
     height: 19px; 
     width: 115px; 
     margin: 1px 20px 0 0; 
     a { 
      background: url("images/logo.png") no-repeat scroll 0 0 transparent; 
      float: left; 
      height: 19px; 
      text-indent: -9999px; 
      width: 115px; 
     } 
    } 
} 

但由于某些原因,在第一输入键入“正确的”,并点击提交后,我仍然得到“无效”。信息。任何建议来解决这个问题?

+0

$ j可以附加$ J( “#寄存器形式>表 ”)我认为 – galchen

回答

2

寄存器形式是ID不是一类使用#代替.

$("#register-form form").submit(function() {

此外,我不知道什么是$j使用$jQuery

看到一个工作演示这里http://jsfiddle.net/mEUMr/2/

确保加载jQuery和使用$(doument).ready()

+0

它的工作,但(“ 注册表单形式。”)当我按下提交按钮时,表单没有被提交(只有窗口出现)。这是为什么? – alexchenco

+0

删除'e.preventDefault();'这一行从小提琴代码 – Usman

1

它工作正常,但是有几点RE代码(刚才提到的乌斯曼已发布了类似的回答) - 见我的版本:

http://jsfiddle.net/HWanY/

  1. 您正在使用$j(),而不是$(),但是你可能没有冲突();?
  2. 您的分区#register-form未关闭
  3. 您的bbp-username等字段未关闭div,并为空。
  4. 甚至没有提交按钮。
  5. 另外,最后,确保你的jQuery包含。

除此之外,正如你可以在我的小提琴中看到的那样(现在提交时也提供了窗口提醒),代码在格式正确时工作正常。

你的JS将需要:

$j("#register-form form").submit(function() { 
    if ($j("input:first").val() == "correct") { 
    $j("#registration-notification").animate({ 
      height: "21px", 
      opacity: 1, 
      'padding-top': "8px" 
     }, 800); 
    return true; 
    }else{ 
    $j("span").text("Not valid!").show().fadeOut(1000); 
    return false; 
    } 
}); 
+0

我认为现在是工作,但形式没有被实际提交当我按下提交(仅适用于Windows的出现)。如何解决这个问题? – alexchenco

+0

查看更新的答案 – rickyduck