根据这个三个文本框传值的例子做了个计算器,刚做出来AC功能,有没有大佬完善一下?
<!DOCTYPE html>
<html>
<head>
<title> 计算器</title>
<script type="text/javascript">
var str = '';
function btn(x){
if(x ==''){
jieguo.value = '';
str='';
}else if(x !== "="){
str += x + '';
jieguo.value = str;
}else{
jieguo.value = eval(str);
}
}
</script>
</head>
<body>
<input type="text" id="jieguo" readonly value="">
<br>
<button type="button" onclick="btn('1')">1</button>
<button type="button" onclick="btn('2')">2</button>
<button type="button" onclick="btn('3')">3</button>
<button type="button" onclick="btn('+')">+</button>
<button type="button" onclick="btn('')">AC</button>
<br>
<button type="button" onclick="btn('4')">4</button>
<button type="button" onclick="btn('5')">5</button>
<button type="button" onclick="btn('6')">6</button>
<button type="button" onclick="btn('-')">-</button>
<br>
<button type="button" onclick="btn('7')">7</button>
<button type="button" onclick="btn('8')">8</button>
<button type="button" onclick="btn('9')">9</button>
<button type="button" onclick="btn('*')">*</button>
<br>
<button type="button" onclick="btn('0')">0</button>
<button type="button" onclick="btn('.')">.</button>
<button type="button" onclick="btn('/')">/</button>
<button type="button" onclick="btn('=')"> =</button>
</body>
</html>
根据这个文本框传值做了个计算器,刚做出来AC功能,有没有大佬完善一下?