我在 if...else 语句中设置一个变量。但是,当我尝试在另一个函数中调用该变量时,我收到未定义该变量的错误。如何设置全局变量?
function username_check(){
username = $('#username').val();
if(username == "" || username.length < 7 || username.indexOf(' ') > -1){
usernameFilled = 0;
else{
usernameFilled = 1;
}
}
function email_check(){
email = $('#email').val();
if(email == "" || email.indexOf(' ') > -1) {
emailFilled = 0;
}else{
emailFilled = 1;
}
}
function password_length(){
password = $('#password').val();
if(password == "" || password.indexOf(' ') > -1) {
passwordFilled = 0;
}else{
passwordFilled = 1;
}
}
function password_check(){
password2 = $('#password2').val();
password = $('#password').val();
if(password2.length > 7 && password2 == password) {
password2Filled = 1; /**setting the variable**/
}else{
password2Filled = 0;
}
}
function upload(){
if (usernameFilled == 0 || emailFilled == 0 || passwordFilled == 0 || password2Filled == 0) {
alert('All fields are required');
}else{
/**upload to database**/
}