21 Specify the number of times loops
1: <script>
2: <!--
3: var myArray = new Array(3);
4: myArray[0] = “Item 0”;
5: myArray[1] = “Item 1”;
6: myArray[2] = “Item 2”;
7: for (i = 0; i < ; i++) {
8: (myArray[i] + “<br>”);
9: }
10: // -->
11: </script>
22 Set future execution
1: <script>
2: <!--
3: function hello() {
4: (“Hello”);
5: }
6: (“hello()”,5000);
7: // -->
8: </script>
23 Timed execution function
1: <script>
2: <!--
3: function hello() {
4: (“Hello”);
5: (“hello()”,5000);
6: }
7: (“hello()”,5000);
8: // -->
9: </script>
24 Cancel the timing execution
1: <script>
2: <!--
3: function hello() {
4: (“Hello”);
5: }
6: var myTimeout = (“hello()”,5000);
7: (myTimeout);
8: // -->
9: </script>
25 Execute functions when page uninstallation
1: <body onUnload=”functionName();”>
2: Body of the page
3: </body>
JavaScript is just like that 2: Browser output
26 Access document object
1: <script language=”JavaScript”>
2: var myURL = ;
3: (myURL);
4: </script>
27 Dynamic output HTML
1: <script language=”JavaScript”>
2: (“<p>Here's some information about this document:</p>”);
3: (“<ul>”);
4: (“<li>Referring Document: “ + + “</li>”);
5: (“<li>Domain: “ + + “</li>”);
6: (“<li>URL: “ + + “</li>”);
7: (“</ul>”);
8: </script>
28 Output line break
1: (“<strong>a</strong>”);
2: (“b”);
29 Output date
1: <script language=”JavaScript”>
2: var thisDate = new Date();
3: (());
4: </script>
30 Time zone for specified date
1: <script language=”JavaScript”>
2: var myOffset = -2;
3: var currentDate = new Date();
4: var userOffset = ()/60;
5: var timeZoneDifference = userOffset - myOffset;
6: (() + timeZoneDifference);
7: (“The time and date in Central Europe is: “ + ());
8: </script>
31 Set date output format
1: <script language=”JavaScript”>
2: var thisDate = new Date();
3: var thisTimeString = () + “:” + ();
4: var thisDateString = () + “/” + () + “/” + ();
5: (thisTimeString + “ on “ + thisDateString);
6: </script>
32 Read URL parameters
1: <script language=”JavaScript”>
2: var urlParts = (“?”);
3: var parameterParts = urlParts[1].split(“&”);
4: for (i = 0; i < ; i++) {
5: var pairParts = parameterParts[i].split(“=”);
6: var pairName = pairParts[0];
7: var pairValue = pairParts[1];
8: (pairName + “ :“ +pairValue );
9: }
10: </script>
Do you think HTML is stateless?
33 Open a new document object
1: <script language=”JavaScript”>
2: function newDocument() {
3: ();
4: (“<p>This is a New Document.</p>”);
5: ();
6: }
7: </script>
34 page jump
1: <script language=”JavaScript”>
2: = “http:///”;
3: </script>
35 Add web page loading progress window
1: <html>
2: <head>
3: <script language='javaScript'>
4: var placeHolder = ('','placeholder','width=200,height=200');
5: </script>
6: <title>The Main Page</title>
7: </head>
8: <body onLoad='()'>
9: <p>This is the main page</p>
10: </body>
11: </html>
JavaScript is just like this 3: Image
36 Read image properties
1: <img src="/”"” name=”myImage”>
2: <a href=”# ” onClick=”()”>Width</a>
3:
37 Dynamically loading images
1: <script language=”JavaScript”>
2: myImage = new Image;
3: = “”;
4: </script>
38 Simple image replacement
1: <script language=”JavaScript”>
2: rollImage = new Image;
3: = “”;
4: defaultImage = new Image;
5: = “”;
6: </script>
7: <a href="/”myUrl"” onMouseOver=” = ;”
8: onMouseOut=” = ;”>
9: <img src="/”"” name=”myImage” width=100 height=100 border=0>
39 Random display of images
1: <script language=”JavaScript”>
2: var imageList = new Array;
3: imageList[0] = “”;
4: imageList[1] = “”;
5: imageList[2] = “”;
6: imageList[3] = “”;
7: var imageChoice = (() * );
8: (‘<img src=”' + imageList[imageChoice] + ‘“>');
9: </script>
40 Image replacement by function implementation
1: <script language=”JavaScript”>
2: var source = 0;
3: var replacement = 1;
4: function createRollOver(originalImage,replacementImage) {
5: var imageArray = new Array;
6: imageArray[source] = new Image;
7: imageArray[source].src = originalImage;
8: imageArray[replacement] = new Image;
9: imageArray[replacement].src = replacementImage;
10: return imageArray;
11: }
12: var rollImage1 = createRollOver(“”,””);
13: </script>
14: <a href=”#” onMouseOver=”document. = rollImage1[replacement].src;”
15: onMouseOut=”document. = rollImage1[source].src;”>
16: <img src="/”"” width=100 name=”myImage1” border=0>
17: </a>
Previous page1234Next pageRead the full text