为什么警告框弹出,即使我输入正确数量的字符串/数据

why is alert box popping out even if I input correct amount of strings/data?

本文关键字:数据 字符串 输入 警告 为什么      更新时间:2023-09-26

我的用户名var验证有问题吗?,我不知道为什么警报框一直弹出,即使我提供了正确的用户名数据:(

 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(){
                          if(username == "" || username.length < 1 || username.length > 30 ||  username.indexOf(' ') != -1){
                            alert("Username is required'n-should not be less than 1 character'n-not greater than 30 characters'n-It may also not contain spaces");
                            return false;
                          }
                          if(password.length < 7 || password.indexOf(' ') !=  -1 ){
                            alert("Password should not be empty'n-should at least be 7 characters");
                            return false;
                          }
                          if(retypepassword != password){
                            alert("re-type password should be the same as the password!");
                            return false;
                          }
                          if(emailaddress == "" || emailaddress.search(emailRegEx) == -1){
                            alert("Email Address is required and should be a valid email address");
                            return false;
                          }
                          if(secondaryemailaddress != emailaddress){
                            alert("Secondary Email address should be the same as the primary email address!");
                            return false;
                          }
                          if(secretquestion == ""){
                            alert("Secret Question is required!");
                            return false;
                          }
                          if(secretanswer == ""){
                            alert("Secret Answer is required!");
                            return false;
                          }
                          if(reffcode == ""){
                            alert("Reference Code is required!");
                            return false;
                          }
                          $(this).dialog("close");
                        }
                   }
                });
            },
            "Log in": function() {
                $(this).dialog("close");
                $('div#loginpopup').dialog({
                  resizable: false,
                  height: 230,
                  width: 350,
                  modal: true
                })
            }
        }
    });
    return false;
 }

验证的逻辑是好的,我猜你会丢失或重置用户名值在同一点或不设置它。

autoOpen: false添加到jQuery UI对话框中。

$('div#loginpopup').dialog({
    autoOpen: false,
    resizable: false,
    height: 230,
    width: 350,
    modal: true
});