毫不客气的修你一脸
看到没有这就是我那强大计算器,别说是你,连我自己都被秀了一脸
既然你这么想知道是怎么实现的,那我就勉为其难的告诉你吧~~~~~~
1.首先
2.然后
3.这样
当当当:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算器</title>
<script type="text/javascript">
window.onload = function(){
var in1 = document.getElementById('input1');
var in2 = document.getElementById('input2');
var se = document.getElementById('select');
var dianji = document.getElementById('btn');
dianji.onclick = function(){
var v1 = in1.value;
var v2 = in2.value;
var v3 = se.value;
if(v1=='' || v2==''){
alert('不能是空的!');
return;
}
if(isNaN(v1) || isNaN(v2)){
alert('输入数字');
return;
}
switch(v3){
case '+':
alert((parseFloat(v1)*100 + parseFloat(v2)*100)/100);
break;
case '-':
alert((parseFloat(v1)*100 - parseFloat(v2)*100)/100);
break;
case '*':
alert((parseFloat(v1)*100 * parseFloat(v2)*100)/10000);
break;
case '/':
alert((parseFloat(v1)*100) / (parseFloat(v2)*100));
break;
default :
break;
}
}
}
</script>
</head>
<body>
<h1>计算器</h1>
<input id="input1" type="text">
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input id="input2" type="text">
<input type="button" value="计算" id="btn">
</body>
</html>