<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style>
*{margin:2px;}
#text #inputText{ 150px; height:40px; border:#06C 1px solid ;margin: 0 auto;}
#numValue { text-align: center; }
#cos {text-align: center;}
input{30px;height:30px;}
</style>
<body>
<div id="text">
<div id="inputText"></div>
<div id="cos"></div>
<div id="numValue"></div>
</div>
<script>
var arr=['1','2','3','+','4','5','6','-','7','8','9','*','0','00','=','/','AC'];
for(var i=0,str=[];i<17;i++){
if(i%4==3){
str.push("<input type='button' value='"+arr[i]+"'/>" + "</br>")
}
else{
str.push("<input type='button' value='"+arr[i]+"'/>")
}
}
var inputText = document.getElementById('inputText')
var numValue = document.getElementById('numValue')
numValue.innerHTML= str.join('')
for(var j=0;j<17;j++){
document.getElementsByTagName("input")[j].id=j;
document.getElementsByTagName("input")[j].onclick=function(){
if(this.id==14){
var cos = document.getElementById('cos')
cos.innerText = inputText.innerHTML+"="+eval(inputText.innerHTML)
inputText.innerText=eval(inputText.innerHTML)
}
else if(this.id==16){inputText.innerHTML=''}
else inputText.innerHTML+=this.value;
}}
</script>
</body>
</html>