qq_慕先生0585124
2019-11-12 16:46
<!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功能,有没有大佬完善一下?
仅针对界面做的调整,head标签中加入style样式
<style type="text/css"> button{ width: 40px;} input{ margin:10px 0px;} </style>
button位置不是很齐,界面有大佬能优化一下吗
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题