I. If statement
Example:
<% -- Javascript Learning -- %>
< Script Type = "Text/JavaScript" Language = "JavaScript" >
// If statement
Function Funshowif ()
{
VaR A = 1 ;
VaR B = A ++ ;
If ( > B)
{
Window. Alert ( + ' > ' + B );
}
Else
{
Window. Alert ( + ' < ' + B );
}
}
</ Script >
<% -- Button used for testing -- %>
< Input ID = "Button1" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Funshowif ();" />
2. The variable is empty.
If a variable is defined but no value is assigned, the X type is undefined. If you want to check whether X is defined, use X = NULL () or typeof (x) = 'undefined' (the type is undefined ). Example:
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function Funifnull ()
{
VaR X;
If (X = Null )
{
Alert ( " X is null! " );
}
}
Function Funifundefine ()
{
VaR X;
If ( Typeof (X) = ' Undefined ' )
{
Alert ( " X is null! " );
}
}
Function Funifsign ()
{
VaR X;
X = ()
If ( Typeof (X) = ' Undefined ' )
{
Alert ( " X is null! " );
}
}
</ Script >
<% -- Button used for testing -- %>
< Input ID = "Button1" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Funifnull ();" />
< Input ID = "Button2" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Funifundefine ();" />
III:? : Statement
Example:
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function Funifsign ()
{
VaR X;
VaR A = 0 ; B = 3 ;
X = ( > B) ? " A> B " : " A <B " ;
Alert (X );
}
</ Script >
<% -- Button used for testing -- %>
< Input ID = "Button1" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Funifsign ();" />
result: A