<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<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 oBen = document.getElementById('btn');
oBen.onclick = function () {
var val01 = oInput01.value;
var val02 = oInput02.value;
var s = oSelect.value;
switch (oSelect.value) {
case '0':
alert((parseFloat(val01)*100 +
parseFloat(val02)*100)/100);
break;
case '1': // -
break;
case '2': // *
break;
case '3': // /
break;
}
}
}
</script>
</head>
<body>
<h1>计算器</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="计算" id="bth" />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
/*
* 对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'
*/
var score = parseInt(prompt('请输入成绩'));
switch (true) {
case score>=60:
alert('合格');
break;
default:
alert('不合格');
break;
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
/*
* 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
*/
var today = parseInt(prompt('请输入1-7:'));
switch (today) {
case today = 1:
alert('星期一');
break;
case today = 2:
alert('星期二');
break;
case today = 3:
alert('星期三');
break;
case today = 4:
alert('星期四');
break;
case today = 5:
alert('星期五');
break;
case today = 6:
alert('星期六');
break;
case today = 7:
alert('星期日');
break;
default:
alert('非法参数')
}
</script>
<body>
</body>
</html>
网友评论