计算器
<!DOCTYPE html>
<html lang="en">
<head>
<title>计算器</title>
<meta charset="UTF-8">
<script type="text/javascript">
window.onload = function(){
var number1 = document.getElementById('num1');
var number2 = document.getElementById('num2');
var operator = document.getElementById('opt');
var button = document.getElementById('but');
var Delete = document.getElementById('del');
button.onclick = function(){
var num3 = number1.value;
var num4 = number2.value;
if(num3==''||num4==''){
alert('计算数字不能为空')
return
}
if(isNaN(num3)||isNaN(num4)){
alert('不能输入非数字类型')
return
}
switch(operator.value){
case '+':
alert((parseFloat(num3)*100 + parseFloat(num4)*100)/100);
break;
case '-':
alert((parseFloat(num3)*100 - parseFloat(num4)*100)/100);
break;
case '*':
alert((parseFloat(num3)*100 * parseFloat(num4)*100)/100);
break;
case '/':
if(num3!=0){
alert((parseFloat(num3)*100 / parseFloat(num4)*100)/100);
break;
}
else{
alert('除数不能为零')
}
}
}
Delete.onclick = function(){
var num3 = number1.value;
var num4 = number2.value;
if(num3!=''||num4!=''){
number1.value = ''
number2.value = ''
return
}
}
}
</script>
</head>
<body>
<input type='text' name=' ' placeholder='0000000000' id='num1'>
<select id='opt'>
<option value='+'>+</option>
<option value='-'>-</option>
<option value='*'>*</option>
<option value='/'>/</option>
</select>
<input type='text' name=' ' placeholder='0000000000' id='num2'>
<input type='button' name=' ' value='计算' id='but'>
<input type='button' name='' value='归零' id='del'>
</body>
</html>