1
1
mirror of https://github.com/zserge/awfice.git synced 2024-10-03 22:37:24 +03:00
awfice/calculator.html
zhouquan 8120d641ed
new page: add calculator page 🧮 (#35)
* new page: add calculator page 🧮

* remove whitespaces

Co-authored-by: zhouLion <zhouquan147369@gamil.com>
2021-08-12 17:06:42 +02:00

1 line
657 B
HTML

<table style="text-align: center;width:80vw;margin: 0 auto;"><tbody><tr><td colspan="4"><textarea></textarea></td></tr></tbody><script>let d=document;let tbl=d.querySelector('tbody');let z=d.querySelector('textarea');let oc=(x)=>z.value+=x;let cl=()=>z.value='';let re=()=>{try{z.value=eval(z.value);}catch(error){cl();}};[[1,2,3,'+'],[4,5,6,'-'],[7,8,9,'*'],['C',0,'=','/']].forEach((a)=>{let r=d.createElement('tr');r.style.lineHeight='64px';tbl.appendChild(r);a.forEach((b)=>{let tb=d.createElement('tb');tb.innerText=b;tb.style.padding='16px';tb.style.border='1px solid';r.appendChild(tb);tb.onclick=b==='='?re:b==='C'?cl:()=>oc(b);})})</script></table>