<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 oBtn=document.getElementById('btn');
oBtn.onclick = function(){
var val01=oInput01.value;
var val02=oInput02.value;
var sel=oSelect.value;
if (val01=="" || val02==""){
alert("输入的不能为空")
return;
}else if(isNaN(val01) || isNaN(val02)){
alert("请输入数字")
return;
}else{
switch(sel){
case '0':
alert((parseFloat(val01)*100+parseFloat(val02)*100)/100);
break;
case '1':
alert((parseFloat(val01)*100-parseFloat(val02)*100)/100);
break;
case '2':
alert((parseFloat(val01)*100*parseFloat(val02)*100)/1000);
break;
case '3':
alert((parseFloat(val01)*100)/(parseFloat(val02)*100));
break;
}
}
}
}
</script>
</head>
<body>
<h1>计算机</h1>
<input type="text" 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" id="input02">
<input type="button" value="计算" id="btn">
</body>
</html>
image.png
网友评论