With statement
The with statement is usually used to shorten the number Code Quantity. When Program If you use the attributes or methods of an object multiple times, you can use with to call the object in with without adding the object. Object method or attribute before the call.
Format:
With (Object Name)
{
Execution statement Block
}
Instance:
<% -- Javascript Learning -- %>
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function Demodate ()
{
VaR SSTR;
VaR Ddate = New Date ();
With (Ddate)
{
// The original format is ddate. getyear (). Here, with is abbreviated as getyear ()
SSTR = Getyear () + " Year " ;
SSTR + = Getmonth () + " Month " ;
SSTR + = Getdate () + " Day " ;
SSTR + = Gethours () + " Hour " ;
SSTR + = Getminutes () + " Minute " ;
SSTR + = Getseconds () + " Seconds " ;
}
Return SSTR;
}
Function Persionshow ()
{
// Call a function
Alert ( " Date: " + Demodate ());
}
</ Script >
<% -- Button used for testing -- %>
< Input ID = "Button1" Type = "Button" Runat = "Server" Value = "Test" Onclick = "Persionshow ();" />