1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
window.onload = function () {
var oInput01 = document.getElementById('input01');
var oInput02 = document.getElementById('input02');
var oSelect = document.getElementById('select');
var oBtn = document.getElementById('btn');
oBtn.onclick = function () {
var vl01 = oInput01.value;
var vl02 = oInput02.value;
if (vl01=="" || vl02==""){
alert('輸入不能為空嗤疯!');
return;
}
if (isNaN(vl01) || isNaN(vl02)){
alert('請輸入數(shù)字择示!');
return;
}
switch(oSelect.value){
case '0':
alert((parseFloat(vl01)*100 + parseFloat(vl02)*100)/100);
break;
case '1':
alert((parseFloat(vl01)*100 - parseFloat(vl02)*100)/100);
break;
case '2':
alert((parseFloat(vl01)*100) * (parseFloat(vl02)*100)/10000);
break;
case '3':
alert((parseFloat(vl01)*100) / (parseFloat(vl02)*100));
break;
}
}
}
</script>
</head>
<body>
<h1>計(jì)算器</h1>
<input type="text" name="" id="input01">
<select id="select">
<option value="0">+</option>
<option value="1">-</option>
<option value="2">*</option>
<option value="3">/</option>
</select>
<input type="text" name="" id="input02" />
<input type="button" name="" value="計(jì)算" id="btn">
</body>
</html>
2
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch練習(xí)1</title>
<script type="text/javascript">
/*
* 對(duì)于成績大于等于60分的细睡,輸出'合格'。低于60分的图谷,輸出'不合格'
*/
var score = Number(prompt("請輸入成績:"))
switch(parseInt(score/60)){
case 1:
alert('合格');
break;
case 0:
alert('不合格');
break;
}
</script>
<body>
</body>
</html>
3
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch練習(xí)2</title>
<script type="text/javascript">
/*
* 從鍵盤接收整數(shù)參數(shù)驮宴,如果該數(shù)為1-7掐松,打印對(duì)應(yīng)的星期附帽,否則打印非法參數(shù)。
*/
var num = Number(prompt("numbe"))
switch(num){
case num = 1:
alert('sunday')
break;
case 2:
alert('monday');
break;
case 3:
alert('tuesday');
break;
case 4:
alert('Wednesday');
break;
case 5:
alert('Thursday');
break;
case 6:
alert('Friday');
break;
case 7:
alert('Saturday');
break;
default:
alert('erro');
break;
}
</script>
<body>
</body>
</html>