按钮在那里时不会隐藏div,为什么?

时间:2011-08-11 08:26:23

标签: jquery

这是我的代码

 if(userid == ""){
        $( "#dialog:ui-dialog" ).dialog( "destroy" );

        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height: 230,
        width: 350,
            modal: true,
            buttons: {
                "Register": function(){
                    $(this).dialog("close");
                $('div#registerpopup').dialog({
                   resizable: false,
                   height: 485,
                   width: 420,
                   modal: true,
                   buttons: {
                      "Register" : function(){
                        var valid = true;
                        valid = valid && checkLength(username,"Username",1,30);
                        valid = valid && checkPassword(password,"Password",7,);
                        valid = valid && checkRetype(password,retypepassword);
                        valid = valid && checkRegexp(emailaddress,emailRegex,"Emailaddress");
                        valid = valid && checkSecretquestion(secretquestion,"Secret Question");
                        valid = valid && checkSecretquestion(secretanswer,"Secret Answer");
                        if(valid){
                          $.ajax({
                             type: "POST",
                             url: "classes/ajax.registerpopup.php",
                             timeout: 8000,
                             data: "username="+username+"&password="+password+"&emailaddress="+emailaddress+
                                  "&secretquestion="+secretquestion+"&secretanswer="+secretanswer,
                             success: function(){
                                alert("you are registered now");
                             }
                          });
                          return false;
                        }
                      }
                   }
                });
                },
                "Log in": function() {
                    $(this).dialog("close");
                $('div#loginpopup').dialog({
                  resizable: false,
                  height: 230,
                  width: 350,
                  modal: true
                })
                }
            }
        });
    return false;
 }

这是所谓的隐藏的div

<div id="dialog-confirm" title="Register OR Login">
    <p>Before you can submit your cv,<br />please log in or register,registering only takes 2 seconds
    and you will not lose the information you have entered.</p>
</div>

          <div id="registerpopup" title="Register" class="form" style="background: #F0F0F0;">
                <p class="validateTips">All form fields are required.</p>

                <form>
                  <table>
                    <tr>
                     <td><label>Username</label></td>
                     <td><input type="text" name="username" id="username" size="12"/></td>
                    </tr>
                    <tr>
                     <td><label>Password</label></td>
                     <td><input type="password" name="password" id="password" size="10" value=""/></td>
                    </tr>
                    <tr>
                     <td><label>Re-type Password</label></td>
                     <td><input type="password" name="retypepassword" id="retypepassword" size="10" value=""/></td>
                    </tr>
                    <tr>
                     <td><label>Email Address</label></td>
                     <td><input type="text" name="emailaddress" id="emailaddress" value=""/></td>
                    </tr>
                    <tr>
                     <td><label>Secondary Email Address</label></td>
                     <td><input type="text" name="secondaryemailaddress" id="secondaryemailaddress" value=""/></td>
                    </tr>
                    <tr>
                    <td><label>Secret Question</label></td>
                    <td><input type="text" name="secretquestion" id="secretquestion" value="" /></td>
                    </tr>
                    <tr>
                     <td><label>Secret Answer</label></td>
                     <td><input type="secretanswer" name="secretanswer" id="secretanswer" value=""/></td>
                    </tr>
                    <tr>
                    <td><label>Reff. Code</label></td>
                    <td><input type="text" name="reffcode" id="reffcode" value="" /></td>
                    </tr>
                  </table>
                </form>
          </div>

现在我的问题是,当我放置$('div #registerpopu).dialog({})的按钮参数时,为什么会出现所谓隐藏的div? ,但当按钮不在那里时,div被隐藏了,我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

尝试将style="display:none;"添加到您想隐藏的divs,如下所示:

<div id="dialog-confirm" title="Register OR Login" style="display:none;">
    <p>Before you can submit your cv,<br />please log in or register,registering only takes 2 seconds
    and you will not lose the information you have entered.</p>
</div>

我希望这会有所帮助。