<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function celement() {
var value1 = document.getElementById("va1").value;
var value2 = document.getElementById("va2").value;
var tich = document.getElementById("select").value;
var result;
// if(tich=="+"){
// result = parseFloat("value1") + parseFloat("value2");
// }
// else if(tich=="-"){
// result = parseFloat("value1") - parseFloat("value2");
// }
// else if(tich=="*"){
// result = parseFloat("value1") * parseFloat("value2");
// }
// else{
// result = parseFloat("value1") / parseFloat("value2");
// }
switch (tich) {
case "+":
result = parseFloat("value1") + parseFloat("value2");
break;
case "-":
result = parseFloat("value1") - parseFloat("value2");
break;
case "*":
result = parseFloat("value1") * parseFloat("value2");
break;
default:
result = parseFloat("value1") / parseFloat("value2");
break;
}
document.getElementById("incon").value = result;
}
</script>
</head>
<body>
<!--计算器-->
<br> 计算器:
<br>
<input type="text" name="" id="va1" value="" />
<select name="" id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="" id="va2" value="" />
<input type="button" name="" id="" value="=" onclick="celement()" />
<input type="text" name="" id="incon" value="" />
</body>
</html>
已知道了
parseFloat()内不加“”