<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="lianxi.css">
<script type="text/javascript">
window.onload = function(){
var oIp = document.getElementById("input01");
var oIp2 = document.getElementById("input02");
var oSelect = document.getElementById("select");
var oBtn = document.getElementById("btn");
oBtn.onclick = function(){
var val01 = oIp.value;
var val02 = oIp2.value;
var sel = oSelect.value;
if(val01=="" || val02==""){
alert("输入内容不能为空");
return;
}
if(isNaN(val01) || isNaN(val02)){
alert("请输入数字");
return;
}
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))/10000);
break
case"3":
alert((parseFloat(val01)*100)/(parseFloat(val02)*100));
break
}
}
}
</script>
</head>
<body>
<h1>计算器</h1>
<div id="content">
<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">
<button type="submit" id="btn">计算</button>
</div>
</body>
</html>
任意一个输入为空时:

任意一个不是数字时:



数字加减乘除:




小数的加减乘除:



网友评论