毫不客氣的修你一臉
看到?jīng)]有這就是我那強大計算器疚膊,別說是你义辕,連我自己都被秀了一臉
既然你這么想知道是怎么實現(xiàn)的,那我就勉為其難的告訴你吧~~~~~~
1.首先
2.然后
3.這樣
當(dāng)當(dāng)當(dāng):
<!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('輸入數(shù)字');
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>