2017-04-19 3 views
0

私のローカルデータベースにはlocalstoragedbが使用されています。しかし、form return falseのいずれかを送信しても、フォームの送信が停止することはありません。 はここreturn false localstoragedbで作業していません

$("#registration").on("submit", function(e) { 
    e.preventDefault(); 
    if ($('#username').val() === '') { 
     $('#username').parent().addClass('error'); 
     return false; 
    }; 
    if ($('#password').val() === '') { 
     $('#password').parent().addClass('error'); 
     return false; 
    }; 
    if ($('#mobile').val() === '') { 
     $('#mobile').parent().addClass('error'); 
     return false; 
    }; 

    localDb.queryAll("UserInfo"); 
    localDb.queryAll("UserInfo", { 
     query: function(row) { 
      if (row.username === $('#username').val()) { 
       alert("username already existed"); 
       return false; 
      } 

     } 

    }); 


    localDb.insert("UserInfo", { 
     username: $('#username').val(), 
     password: $('#password').val(), 
     Mobile: $("#mobile").val() 
    }); 
    localDb.commit(); 
    $(".message").show(); 
    setTimeout(function() { 
     window.location.replace("login.html"); 
    }, 2000); 

}); 

すべての帰り支保工正しくlocalDb.queryAll関数内以外.....コードです。 それは私に警告するユーザー名はすでに存在しましたが、フォームも提出しました。 return falseで問題が発生しました。 私は行方不明か間違っていますか? ありがとうございました.........

答えて

0

私はループ内で間違いを犯しましたが、特定の値をすべての行で検索し続け、挿入することができない場所を探し続けました。正しいコードはここにあります....

$("#registration").on("submit", function(e) { 
    e.preventDefault(); 
    if ($('#username').val() === '') { 
     $('#username').parent().addClass('error'); 
     return false; 
    }; 
    if ($('#password').val() === '') { 
     $('#password').parent().addClass('error'); 
     return false; 
    }; 
    if ($('#mobile').val() === '') { 
     $('#mobile').parent().addClass('error'); 
     return false; 
    }; 

    localDb.queryAll("UserInfo"); 
    localDb.queryAll("UserInfo", { 
     query: function(row) { 
      if (row.username === $('#username').val()) { 
       alert("username already existed"); 
       return false; 
      } 

     } 

    }); 


    localDb.insert("UserInfo", { 
     username: $('#username').val(), 
     password: $('#password').val(), 
     Mobile: $("#mobile").val() 
    }); 
    localDb.commit(); 
    $(".message").show(); 
    setTimeout(function() { 
     window.location.replace("login.html"); 
    }, 2000); 

}); 
関連する問題