我重新创建了我的移动应用程序,这次我尝试使用CLI开发,这样我就可以用最简单的方法在Phonegap 3.4中添加插件。
问题是在我的JavaScript中,当我调用registerdb
函数时,没有什么工作正常。我的意思是,即使我在运行密码或电子邮件文本区域时出错,我也不会得到任何振动或错误消息。
当我发表评论registerdb
和函数的调用时,JavaScript工作正常直到它结束(它在每个文本输入都正确时打印警报)。
所以,我认为这个问题与调用函数registerdb
有关。有什么帮助吗?
<小时/> 我的
.js
文件:
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
// Empty
}
// Function to add event listener to register button
function load() {
var el = document.getElementById("register");
el.addEventListener("click", Register, false);
}
document.addEventListener("DOMContentLoaded", load, false);
function Register() {
var username = document.getElementsByName('username')[0];
var password = document.getElementsByName('password')[0];
var email = document.getElementsByName('email')[0];
if (username.value == "") {
$("#username").focus();
document.getElementById('username').style.boxShadow = "0 0 7px #f00";
navigator.notification.vibrate(500);
}
else{
document.getElementById('username').style.boxShadow = "none";
}
//>5 characters, 1 upper case, at least 1 lower case, at least 1 numerical character, at least 1 special character
var passExp = /(?=^.{6,15}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*/;
var strong_flag_pass = 0;
if (!(password.value.match(passExp))) {
$("#password").focus();
document.getElementById('password').style.boxShadow = "0 0 7px #f00";
navigator.notification.alert("Please enter a strong Password! It has to have at least: 6 characters, 1 upper case, 1 lower case, 1 numerical character and 1 special character!", null, 'Password', 'Okay');
navigator.notification.vibrate(500);
strong_flag_pass = 0;
}
else{
document.getElementById('password').style.boxShadow = "none";
strong_flag_pass = 1;
}
var emailExp = /^.+@[^\.].*\.[a-z]{2,}$/;
var strong_flag_email = 0;
if (!(email.value.match(emailExp))) {
$("#email").focus();
document.getElementById('email').style.boxShadow = "0 0 7px #f00";
navigator.notification.alert("Please enter a correct Email!", null, 'Email', 'Okay');
navigator.notification.vibrate(500);
strong_flag_email = 0;
}
else {
document.getElementById('email').style.boxShadow = "none";
strong_flag_email = 1;
}
var gender = document.getElementById("gender").value;
var about_me = document.getElementById("about-me").value;
var age = document.getElementById("radio-choice").value;
if (document.getElementById('radio-choice-1').checked) {
age = document.getElementById('radio-choice-1').value;
}
else if (document.getElementById('radio-choice-2').checked) {
age = document.getElementById('radio-choice-2').value;
}
else if (document.getElementById('radio-choice-3').checked) {
age = document.getElementById('radio-choice-3').value;
}
else if (document.getElementById('radio-choice-4').checked) {
age = document.getElementById('radio-choice-4').value;
}
else if (document.getElementById('radio-choice-5').checked) {
age = document.getElementById('radio-choice-5').value;
}
else if (document.getElementById('radio-choice-6').checked) {
age = document.getElementById('radio-choice-6').value;
}
if (username.value != "" && strong_flag_pass == 1 && strong_flag_email == 1){
alert(gender);
alert(about_me);
alert(age);
//add to db
registerdb(email, password, username, gender, about_me, age);
}
function registerdb(email, password, username, gender, about_me, age) {
alert(gender);
alert(about_me);
alert(password;
}
}
以我.html
的方式拨打电话&#34;这个功能是:
<a href="#" id="register" data-role="button" data-theme="a">Register</a>
答案 0 :(得分:0)
在)
alert(password;
function registerdb(email, password, username, gender, about_me, age) {
alert(gender);
alert(about_me);
alert(password);
}