Académique Documents
Professionnel Documents
Culture Documents
7/27/12
7/27/12
</body>
7/27/12
<body> <script language=JavaScript> // This is a one-line comment document.write(Hello); /* This is a multiline comment */ </script>
7/27/12
7/27/12
<body> <script document.write(Hello language=JavaScript> ); <!-{ document.write( document.write(Hello); there); document.write( there); document.write(.); } // --> } </script> </body> if (condition) {
7/27/12
if you issue the following document.write command: document.write(<strong>Hello</str ong>); the browser receives the following HTML and renders it: <strong>Hello</strong> { document.writeln(a);
7/27/12
var myVariable; ... myVariable = some value; var myVariable = some document.write(myVari value; able);
7/27/12
String
var aVar = This is a string; Concatenating Strings var myVariable = ab + cd; Makes myVariable = abcd .
7/27/12
variableName.search(is); <body> <script language=JavaScript> <!-var myVariable = Hello there; var therePlace = myVariable.search(there); 7/27/12
Strings
Replacing Text in Strings thisVar.replace(Monday,Friday); big: Returns the string in big tags blink: Returns the string in blink tags bold: Returns the string in b tags fixed: Returns the string in tt tags (for fixed-width display) 7/27/12
italics: Returns the string in i tags small: Returns the string in small tags strike: Returns the string in strike tags (for a strikethrough effect) sub: Returns the string in sub tags (for a subscript effect) sup: Returns the string in sup tags 7/27/12 a superscript effect) (for
document.write(myVariable.big() + <br>); document.write(myVariable.blink() + <br>); document.write(myVariable.bold() + <br>); document.write(myVariable.fixed() + <br>); document.write(myVariable.fontcolor (red) + <br>);
7/27/12
Arrays
var arrayName = new Array(number of elements); arrayName[0] = value 1; var arrayName = new Array(value 1, value 2, value 3, etc.) arrayName.sort(); document.write(myArray.sort()); The elements will be separated by commas
7/27/12
7/27/12
First element,Second element,Third element var thisVar = First element,Second element,Third element; var anotherVar = thisVar.split(,);
7/27/12
Functions
7/27/12
<body> <script language=JavaScript> <!-var result = window.confirm(Click OK to continue); var userChoice = window.confirm(Choose OK or Cancel); if (userChoice == true) {
7/27/12
document.write(OK);
7/27/12
</head>
<head> <script language=JavaScript> function functionName() { Code to execute when the page finishes loading } </script> </head> 7/27/12
Loops
for (i = 1; i <= 10; i ++) { Code to execute in the loop } while (condition) { JavaScript command JavaScript command etc. }
7/27/12
function functionName() { some JavaScript code window.setTimeout(functionName() ,schedule time); } window.setTimeout(functionName() ,schedule time);
7/27/12
7/27/12
<body onUnload=functionName();> Body of the page </body> Check If Java Is Enabled with JavaScript var haveJava = 7/27/12 navigator.javaEnabled();
<body> <script language=JavaScript> <!-var haveJava = navigator.javaEnabled(); // --> </script> </body> 7/27/12