Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies. Quick Reference - Vander

Vander Javascript for dummies. Quick Reference - Wiley Publishing, 2002. - 115 p.
Download (direct link): javascriptquickreference2002.pdf
Previous << 1 .. 32 33 34 35 36 37 < 38 > 39 40 41 42 43 44 .. 72 >> Next

Syntax:
dateObjectName. getMinutes()
Example:
var today = new Date() // gets today’s date
var numberMinutesAfterTheHour = today.getMinutes()
getMonth
Use the getMonth () method of a Date object to access the month of the year associated with a specified date. For example, if the Date object represents Wednesday, the 26th of June, 1996, at 3:45 p.m., getMonth () returns the value 5.
For a date of June, you’d think getMonth () would return 6, пШщ wouldn’t you? Well, unfortunately, it returns 5. That’s because
JavaScript counts January as month 0, February as month 1, and so on.
Syntax:
dateObjectName.getMonth()
Example:
var today = new Date() // gets today's date var month = today.getMonth()
getSeconds
Use the getSeconds () method of a Date object to access the number of seconds in the specified date. For example, if the Date object represents Wednesday, the 26th of June, 1996, at 3:45:16 p.m., getSeconds () returns the value 16.
Syntax:
dateObjectName.getSeconds()
getTime
Example:
var today = new DateO // gets the current date var seconds = today.getSeconds()
getTime
Use the g e t T i m e () method of a D a t e object to access the number of milliseconds that have elapsed since January 1, 1970, at 00:00:00 (no, I’m not kidding!). About the only use that regular folks are going to have for this method is to assign one time to another, like this: timeToLeave = today. getTime() (That way you never have to actually look at and decipher the darn thing.)
Versions of Navigator earlier than 3.0 (and some early beta versions of Internet Explorer Version 3.0) tend to — well — blow up if they encounter a date earlier than January 1,1970. So avoid giving these browsers a date like this! If you’re running anything other than Navigator 3.0 and want to work with dates older than 1970, try using a more recent date (say, 1980) and then doing subtraction by using regular variables (as opposed to Date objects). See also the “Date” section in Part IV.
Syntax:
dateObjectName. getTime()
Example:
var startDay = new DateO // gets the current date var startTime = today.getTimet)
getTimezoneOffset
Use the getTi mezoneOf f set () method of the Date object to get the difference in minutes between the time of the Date object and Greenwich Mean Time (GMT).
Syntax:
dateObjectName.getTimezone0ffset()
Example:
today = new DateO // gets the current date currentTimezoneOffsetlnHours = today. getTimezone0ffset0/60
get\lear
Use the get Yea r () method of a Date object to access the year of the specified date (less 1900). For example, if the Date object represents Wednesday, the 26th of June, 1996, at 3:45:16 p.m., g e t Y e a r () returns the value 96.
inetexOf 105
Syntax:
dateObjectName.getYear()
Example:
var today = new DateO // gets the current date var currentYear = today.getYear()
qo
Use the g о () method of the history object to load a URL from the history list. You can supply g о () with one of the following two parameters:
♦ An integer, which the interpreter uses to count forward (positive integer) or backward (negative integer) from the current list position to find a URL to load
♦ A string that contains a whole URL or just part of a URL; the interpreter finds the nearest matching URL and loads it
Syntax:
hi story.go(de1ta \ "location")
Example:
history.go(3) // loads the third URL forward hi story.go(-2) // loads the second URL back
// loads the closest URL containing the parameter string
hi story.go("www.austi n")
indexOf
Use the i ndexOf () method of the St ri ng object to search a specified string for the occurrence of another specified string. The i ndexOf () method accepts two parameters:
♦ A search value that consists of a string for which to search
♦ An optional index value that tells the interpreter where in the original string to begin searching for the search string (the default value is 0, which means that the search begins — where else? — at the beginning)
i ndexOf () returns the first index of the original string that matches the search string (see the following real-life example). If it can’t find a match at all, it returns
Syntax:
string.! ndexOf (sea rch /a 1 ue, [ fromIndex~\)
italics
Example:
var theResult = "Can you can-can?".indexOf("can")
// theResult is set to 8
Can you can-0123456789 1011
The string “Can you can-can?” is nothing more than an indexed list of characters. As shown in this example, the first occurrence of “can” starts at index 8 — so theResul t is set equal to 8.
italics
Using the i tal i cs () method of the Stri ng object enables you to display an italicized string.
Syntax:
string.i tali cs()
Example:
"IMPORTANT".italicsO
Using the italicsO method produces the same result as surrounding text with the < I > . . . < /1 > HTML tag pair.
jatfaEnabled ()
The javaEnabledO method of the navigator object returns true or false, depending on whether Java is enabled or disabled.
Syntax:
navi gator. javaEnabledO Example:
Previous << 1 .. 32 33 34 35 36 37 < 38 > 39 40 41 42 43 44 .. 72 >> Next