我试图检查所有字段是否都为真所以我创建了一个函数,"其中"是输入字段,"检查"是真的与否。
check_fields(where,check){
var fname = false;
var lname = false;
var email = false;
var email2 = false;
var pass = false;
var pass2 = false;
var gender = false;
if(where == "fname" && check == true){
fname = true;
alert("a");
}else{
fname = false;
}
if(where == "lname" && check == true){
lname = true;
alert("b");
}else{
lname = false;
}
if(where == "email" && check == true){
email = true;
alert("b");
}else{
email = false;
}
if(where == "pass" && check == true){
pass = true;
alert("c");
}else{
pass = false;
}
if(where == "gender" && check == true){
gender = true;
alert("d");
if(fname == true && lname == true && email == true && pass == true){
form_ispass();
alert("HI");
}
}else{
gender = false;
}
}
它确实从a,b,b,c发出警报但是当我检查性别时它会发出警报d。然而,即使所有字段都设置为true,它也不会警告HI。
答案 0 :(得分:0)
您的最终检查位于gender
条件内。将它移到外面:
if(where == "gender" && check == true){
gender = true;
alert("d");
}else{
gender = false;
}
if(fname == true && lname == true && email == true && pass == true){
form_ispass();
alert("HI");
}
答案 1 :(得分:0)
解决了这个问题,为每个输入创建了一个全局变量,当它满足我的要求时,我将其设置为true,每次在输入中键入内容时,总是调用:
from django.db.models import Count
>>> user = User.objects.filter(pk=some_id).annotate(num_followers=Count('followers'))
>>> user
[<User: someuser>]
>>> user[0].id
some_id
>>> user[0].num_followers
123