Home > Web Front-end > JS Tutorial > body text

Web calculator A JS calculator_Other special effects

WBOY
Release: 2016-05-16 17:23:48
Original
1403 people have browsed it

It’s a pretty small JavaScript web calculator. I think the interface is pretty good. After all, it looks good without using any image modifications, and its functions are quite practical. It can complete basic mathematical calculations. Click "Run Code" You can run it to see the effect.


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> <!-- willclear=false //这个变量作为下一次输入是否先清空输入框的状态标志 function backspace(){ //退格 Calc.Input.value = Calc.Input.value.substring(0,Calc.Input.value.length-1) Calc.Input.title = Calc.Input.value.substring(0,Calc.Input.title.length-1) }//取长度为原长度减一的串,实现退格效果。 function addoperator(){ //加操作符 if (willclear){ //如果这次输入前需要清空输入框 willclear=false //先清除标志,避免下次再次被错误地重复清空 clearinput() //清除输入内容 } Calc.Input.value += event.srcElement.innerText //给用于显示的加上刚输入的运算符 Calc.Input.title += event.srcElement.name //给用于计算的表达式区加上刚输入的运算符 } function clearinput(){ //清除输入 Calc.Input.value='' //清空显示区 Calc.Input.title='' //清空表达式 } function result(){ //用于计算结果 Calc.Input.value = eval(Calc.Input.title)//执行表达式区的表达式,返回结果到显示区。 willclear=true//设定下次按键则先清除此次计算结果。 } //--> </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!