0
我正在一个项目中,我从另一个对象/函数引用一个变量。然而,我总是返回false。我不确定我是否正确调用它。总是返回false | Javascript |对象
下面是验证功能:
app.validation = function(){
'use strict';
var validCheck = true;
if((app.process.user.length < 3) || (app.process.user.length > 50)){
validCheck = false;
window.alert("The username is not acceptable. Example: username");
};
if((app.process.name.length < 3) || (app.process.name.length > 50) || (!app.process.name.indexOf(" ") === -1)){
validCheck = false;
window.alert("The name is not acceptable. Example: John Smith");
};
if((app.process.email.length < 3) || (app.process.email.length > 100) || (!app.process.email.indexOf("@") === -1)){
validCheck = false;
window.alert("The email is not acceptable. Example: [email protected]");
};
if((app.process.passlength < 6) || (app.process.pass.length > 20)){
validCheck = false;
window.alert("The password is not acceptable. Example: password");
};
if((app.process.age.length < 1) || (app.process.age.length > 2)){
validCheck = false;
window.alert("The age is not acceptable. Example: 22");
};
return validCheck;
};
这是对变量的存储:
app.process = function(){
'use strict';
var user = document.getElementById("user").value;
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var pass = document.getElementById("pass").value;
var age = document.getElementById("age").value;
var test = app.validation();
console.log(test);
if(!test){
window.alert("Try Again.");
}else{
app.reset();
app.members[app.members.length] = new app.Member(user, name, email, pass, age);
app.printMembers();
};
};
还有更多这个代码但是是到大在这里发表。这是导致问题的两个功能。
数据是在流程方法中还是在全局范围内定义? – hudsond7 2014-10-22 00:54:22
其中,总是在:)全局变量是来自地狱。 – 2014-10-22 01:46:37
谢谢你的帮助。 – hudsond7 2014-10-22 11:46:04