2

我有一个使用 Phonegap 开发的应用程序。当我通过单击 HTC Flyer 的 GO 按钮提交我的 HTML 表单时,该表单正在重置而不是提交。我通过互联网搜索。但我不能很好地回答这类问题或答案。请帮帮我。

<link href="css/form.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/iscroll-lite.js"></script>
<script type="text/javascript" src="js/jqFancyTransitions.1.8.js"></script>
<script type="text/javascript" src="js/jquery.cycle.all.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/service.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/modules/slideshow.js"></script>
<script type="text/javascript" src="js/modules/device.js"></script>
<script type="text/javascript" src="js/modules/register.js"></script>
<div class="box module" id="box_register">
 <div class="box_content">
<form id="loginForm" >
  <div class="box_content_tab">Register</div>
    <div class="box_content_center">
      <div class="form_content">
    <label>Name</label>
      <input id="registerNameFld" type="text" class="form_input_box" />
                <label>Email</label>
              <input id="registerEmailFld" type="text" class="form_input_box" />
                 <label>Password</label>
              <input id="registerPasswordFld" type="password" class="form_input_box" />
                 <label>Confirm Password</label>
               <input id="confirmPasswordFld" type="password" class="form_input_box" />
         <div id="registerBtn" class="form-btn blue-btn" >Submit</div>
              </div>
        </div>
         </form>
     </div>
   </div>
 <script>
$("#box_register").newAccount();
</script>

我的 register.js 文件是

(function($) {
$mod = null;
registerMod = {
 initialize : function() {
   $mod.center();
   $('#registerBtn').click(
    function() {
     if ($("#registerNameFld").val() == ''
       || $("#registerEmailFld").val() == ''
       || $("#registerPasswordFld").val() == ''
       || $('#confirmPasswordFld').val() == '') {
         if($("#registerNameFld").val() == ''
            && $("#registerEmailFld").val() == ''
            && $("#registerPasswordFld").val() == ''
            && $('#confirmPasswordFld').val() == ''){
                alert('Please enter All Fields');
          }
         else if($("#registerNameFld").val() == ''){
            alert('Please enter Username ');
          }
         else if($("#registerEmailFld").val() == ''){
            alert('Please enter Email ');
          }
         else if($("#registerPasswordFld").val() == ''){
             alert('Please enter Password ');
          }
         else if($("#confirmPasswordFld").val() == ''){
             alert('Please enter Confirm Password ');
          }
        }else {
          if(registerMod.isNameValid($("#registerNameFld").val()) == 'correct'){
           if(registerMod.isEmailValid($("#registerEmailFld").val()))
           {
            if($("#registerPasswordFld").val().length >= 6){
             if(registerMod.isPassValid($("#registerPasswordFld").val()) == 'correct'){
              if( $("#registerPasswordFld").val() == $('#confirmPasswordFld').val()){
               if($("#registerPasswordFld").val() ==$("#registerNameFld").val()){
                 alert('Name and Password should not be same');
               }
               else{
                 service.newAccount({
                 name : $("#registerNameFld").val(),
                 email : $("#registerEmailFld").val(),
                 password : $("#registerPasswordFld").val(),
                 device : device
               }, registerMod.onRegisterSuccess, registerMod.onRegisterError);    
             }
             }else{
               alert("Your password and confirmation password do not match.");
             }
       }else if(registerMod.isPassValid($("#registerPasswordFld").val()) == 'special'){
         alert('Password should not contain only special characters');
       }else if(registerMod.isPassValid($("#registerPasswordFld").val()) =='space'){
         alert('Password should not contain spaces');
       }else{
         alert('invalid format of password');
       }
      }
      else{
        alert('Password should contain minimum 6 characters');
      }
     }
     else{
       alert('Please enter valid Email address');
     }
    }
    else if(registerMod.isNameValid($("#registerNameFld").val())=='special'){
    alert('Name should not contain special characters');
     }
  else if(registerMod.isNameValid($("#registerNameFld").val())=='number'){
     alert('Name should not contain only numbers and should not start with numbers');
   }
 else if(registerMod.isNameValid($("#registerNameFld").val())=='invalid'){
     alert('Name should not start with Space');
 }
 }
    return false;
 });
    },
    onRegisterSuccess : function(rep) {
        $('#box_register').fadeOut();
        app.onLogin(rep);
    },
    onRegisterError : function() {
        app.onError();
        alert("Email was already taken");
    },
    isEmailValid:function (mailID) {
        var atpos=mailID.indexOf("@");
        var dotpos=mailID.lastIndexOf(".");
        if(atpos<1 || dotpos<atpos+2 || dotpos+2>=mailID.length){   
            return false; 
        }else{
            return true;
        }
    },
    isNameValid:function (name) {
        var regexCorrect = /^[a-zA-Z]+[0-9]*[!@#$%\^&*(){}[\]<>?\/\-'".,;:+_]*/;
        var regexSpl = /[!@#$%\^&*(){}[\]<>?\/\-'".,;:+_]/;
        var regexNum = /^\d+/;
        if(regexCorrect.test(name)){
            return "correct";
        }else if(regexSpl.test(name)){
            return "special";
        }else if(regexNum.test(name)){
            return "number";
        }else{
            return "invalid";
        }
    },
    isPassValid:function (name) {
        var regSpace = /[\s]/;
        var regexSpl = /^[!@#$%\^&*(){}[\]<>?\/\-'".,;:+_]$/;
        if(regSpace.test(name)){
            return 'space';
        }else if(regexSpl.test(name)){
            alert('matching');
            return 'special';
        }else{
            return 'correct';
        }
    }
};

$.fn.newAccount = function() {
    $mod = $(this);
    registerMod.initialize();
};

})(jQuery);

服务在 service.js 文件中定义

4

0 回答 0