计算器小例子
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<script type="text/javascript">
do{ alert("欢迎使用本计算器");
var s = prompt("请输入计算类型,+ - * /");
var i = prompt("请输入第一个数字");
var j = prompt("请输入第二个数字");
var result;
switch(s){ case "+":
result =Number(i)+Number(j);
break;
case "-":
result =Number(i)-Number(j);
break;
case "*":
result =Number(i)*Number(j);
break;
case "/":
result =Number(i)/Number(j);
break;
default:
result="超出计算类型";
}
}while(confirm(result+";是否继续?"));
</script>
</head>
<body>
</body> </html>