Difference between revisions of "JavaScript: Exemplo de uso do switch"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: <code lang="html"> <html> <head> <title>Minha Página</title> </head> <body> <input type="text" id="txtId" /> <input type="button" id="btOK" value="OK" onclick="javascript:executarF...)
 
 
Line 1: Line 1:
<code lang="html">
+
<code lang="javascript">
 
<html>
 
<html>
 
<head>
 
<head>

Latest revision as of 22:33, 12 September 2008

<html>
	<head>
		<title>Minha Página</title>
	</head>
	<body>
	<input type="text" id="txtId" />
	<input type="button" id="btOK" value="OK" onclick="javascript:executarFuncao();" />
	<script>
		function executarFuncao()
		{
			var i = document.getElementById("txtId").value;
 
			switch(i)
			{
				case "1":
					alert("Um");
					break;
				case "2":
					alert("Dois");
					break;
				case "3":
					alert("Três");
					break;
				case "4":
					alert("Quatro");
					break;
				case "5":
					alert("Cinco");
					break;
				case "6":
					alert("Seis");
					break;
				case "7":
					alert("Sete");
					break;
				case "8":
					alert("Oito");
					break;
				case "9":
					alert("Nove");
					break;
				case "10":
					alert("Dez");
					break;
			}
		}
	</script>
	</body>
</html>