Home > front end >  The value of a variable in the nested conditions why I can't pass?
The value of a variable in the nested conditions why I can't pass?

Time:11-06

As shown in figure:
A initial value is 1
In the outer outlining a=1
Then in the inner outlining, a=0
I thought again when the outer outlining a=1
But a=0,
Solving!!!!!!

CodePudding user response:

Why there are two document here. The onclick, performs a click to do so, the inner onclick not overwrite the first onclick event,,
Why not use directly:
Var a=1;
Document. The onclick=function (event) {
Var obj=event. SrcElement;
If (obj. Name==='teamer') {
A=1;
} else if (obj. Name==='player' & amp; & A==1) {
a=0;
}
}

CodePudding user response:

There is only one variable, you change it, both outer and inner layer, will become the latest value

Var a=1
If (true) {
A=2;
}
Alert (a);//outer layer of a is how much you like it here? Is 1? That a=2 white processing?

CodePudding user response:

Should be so, for example,

Var a=1;
B=a;
If (true) {
A=2;
B=a;
}
Alert (b);//do you think what is outer b here? Is 1? That a=2, b=a not white processing?

CodePudding user response:

reference 1/f, the sensitivity to the fairy response:
why there are two document here. The onclick, performs a click to do so, the inner onclick not overwrite the first onclick event,,
Why not use directly:
Var a=1;
Document. The onclick=function (event) {
Var obj=event. SrcElement;
If (obj. Name==='teamer') {
A=1;
} else if (obj. Name==='player' & amp; & A==1) {
a=0;
}
}

Problem has been solved, thank you
  • Related