开发者

jQuery .submit is not being triggered?

I'm using this code:

$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;
});

on this form (code from firebug):

<div id="register-form">
<form class="bbp-login-form" action="http://localhost/taiwantalkorgfinal2/wp-l开发者_如何学编程ogin.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>

to make this notification appear:

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

But for some reason, after typing 'correct' in the first input and clicking submit, I'm still getting the 'not valid.' message. Any suggestions to fix this?


register-form is an id not a class use # instead of .

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

Also I don't know what is $j use $ or jQuery

See a working demo here http://jsfiddle.net/mEUMr/2/

Make sure to load jQuery and use $(doument).ready()


It works fine, however a few points RE your code (just noted Usman has posted a similar answer) - see my version:

http://jsfiddle.net/HWanY/

  1. You are using $j() as opposed to $(), however you may have noConflict();?
  2. Your div #register-form wasn't closed
  3. Your bbp-username and other fields are not closed div, and empty.
  4. Not even a submit button.
  5. Also, finally, make sure you include jQuery.

Apart from that, as you can see in my fiddle (which now does a window alert on submit as well), the code works fine when correctly formatted.

Your js will need to be:

$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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜