|
|
| Mastering HTML 4 Premium Edition (ISBN: 0782125247) |
 |
List Price: $49.99
Our Price: $34.99
Used Price: $6.95
Release Date: June, 1999
Manufacturer: Sybex (Hardcover)
Sales Rank: 64,920
Author: Deborah S. Ray, Eric J. Ray
|
More Info
|
|
|
Javascript Select Case
|
2003-03-16 12:19:57
|
| |
html
|
|
|
|
|
Category: source:html:javascript
|
|
Description: Example on using switch to select a case.
|
|
Platform: all
|
|
Author: mind
|
|
Viewed: 41090
|
|
Rating: 3.8/5 (131 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
<!-- switch.js - mind (mind@metalshell.com) -->
<!-- example on how to use switch -->
<!-- $ If you have any problems or questions, email me $ -->
<!-- http://www.metalshell.com -->
<!-- put this code into the <head> section of your html document. -->
<!-- start our javascript -->
<script language=JavaScript>
function swExmple()
{
swExmpl(2);
swExmpl(1);
swExmpl(3);
swExmpl("www.metalshell.com");
}
function swExmpl(ex)
{
switch (ex)
{
case 1: { document.write('<font>Caught 1</font><br>'); break }
case 2: { document.write('<font>Caught 2</font><br>'); break }
// And so on.. and so on..
// whatever is passed to switch that is not caught
// by the above fall under this category.
default: { document.write('<font>Error: ' + ex + '</font><br>'); break }
}
}
// end of our javascript
</script>
<!-- place this code anywhere on your html document (example) -->
<!-- align our link below -->
<div align=center>
<!-- make a link that points to our js function printText() -->
<a href="javascript: swExmple();">Click Here!</a>
</div>
|
|
|