The Boolean value true represents True and false for false. The generic relational operator returns the result of a Boolean value. In addition, values of 0,-0, NULL, NaN, undefined, and null characters ("") of special values are interpreted as false, and other values are interpreted as true.
function Ismonth (Mon) {
if ((Mon >= 1) && (Mon <= 12)) {
return true;
} else {
return false;
}
}
if (Ismonth (Mon)) {
Alert ("OK");
} else {
Alert (Please enter the correct month.) ");
}
Boolean = new Boolean (value)
Generates a Boolean object. Set value to the initial value true or FALSE. In order to conform to the idea that "data types can generate objects" in object-oriented form, JavaScript prepares this class, but it is basically useless.
xx = new Boolean (true);
Example
It is useful to use the Boolean value true false to determine the checked of input to cancel and select all check boxes.
Js:
Window.onload=function ()
{
var ainput=document.getelementsbytagname ("input");
Ainput[0].onclick=function ()
{
for (Var i=3;i<ainput.length;i++)
{
Ainput[i].checked=true;
}
};
Ainput[1].onclick=function ()
{
for (Var i=3;i<ainput.length;i++)
{
ainput[i].checked=!ainput[i].checked;
}
};
Ainput[2].onclick=function ()
{
for (Var i=3;i<ainput.length;i++)
{
Ainput[i].checked=false;
}
};
};
Html:
<input type= "button" value= "Select All"/>
<input type= "button" value= "anti-election"/>
<input type= "button" value= "not selected"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>
<br/>
<input type= "checkbox"/>