Think of a fun, run the following javascript:
if (' 0 ') alert ("' 0 ' is true");
if (' 0 ' = = False) alert ("' 0 ' is false"); As a result, two alert! So is ' 0 ' true or false?
The answer is: When you compare JS, there are three rules:
If there is a bool in the comparison, the bool is converted first to the corresponding number, i.e. 0 and 1
If one of the two sides of the comparison is a string, the string is converted to a number
When a string is converted directly to bool, the empty string "is converted to false, except for all strings converted to true
In the first comparison, the ' 0 ' is placed directly in the if expression, which is equivalent to converting the string directly to bool,!! ' 0 ' = = = True, so it is set up
In the second comparison, the false is converted to 0, then the ' 0 ' is converted to 0, the left and right sides are 0, so is also established.
So in the end this is a JavaScript in the time to do the comparison of the type conversion sequence of the problem, the individual think it is not very reasonable, different conversion order results will not be the same
At the time of comparison, use
Whether to publish a self-service system
var rdopromotion=document.getelementsbyname ("Radpromotion");
if (Arraycategory[9])
{
Rdopromotion[0].checked=true;
Rdopromotion[1].checked=false;
}
if (arraycategory[9]== "False")
{
Rdopromotion[0].checked=false;
Rdopromotion[1].checked=true;
}
JS bool True False comparison