自己写的一个计算器

编程入门 行业动态 更新时间:2024-10-08 22:59:46

自己写的一个<a href=https://www.elefans.com/category/jswz/34/1765079.html style=计算器"/>

自己写的一个计算器

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>计算器</title> </head> <body bgcolor="Silver"> <center> All world will give way to you,if you know where is you go. <hr> <span id = "dengyu" style="color: green;font-size: xx-large" mce_style="color: green;font-size: xx-large"></span> <span id = "tai" style="color: green;font-size: xx-large" mce_style="color: green;font-size: xx-large"></span> <span id = "math" style="color: green;font-size: xx-large" mce_style="color: green;font-size: xx-large"></span> <span id = "cumt" style="color: green;font-size: xx-large" mce_style="color: green;font-size: xx-large"></span> <hr> <br> <table> <tr> <td><input type = "button" style="width:25px" value = "1" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "2" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "3" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "+" οnclick="mathClk(this)"> </td> </tr> <tr> <td><input type = "button" style="width:25px" value = "4" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "5" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "6" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "-" οnclick="mathClk(this)"> </td> </tr> <tr> <td><input type = "button" style="width:25px" value = "7" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "8" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "9" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "*" οnclick="mathClk(this)"> </td> </tr> <tr> <td><input type = "button" style="width:25px" value = "0" οnclick="numClk(this)"> </td> <td><input type = "button" style="width:25px" value = "=" οnclick="resultClk()"> </td> <td><input type = "button" style="width:25px" value = "邰" οnclick="writ()"> </td> <td><input type = "button" style="width:25px" value = "/" οnclick="mathClk(this)"> </td> </tr> </table> <br><br> <hr> <span id = "hangzhou" style="font-size: large;font: normal;" mce_style="font-size: large;font: normal;"></span> </center> </body> <script type="text/javascript"> var span_cumt = document.getElementById("cumt"); var span_tai = document.getElementById("tai"); var span_math = document.getElementById("math"); var span_dengyu = document.getElementById("dengyu"); var span_hangzhou = document.getElementById("hangzhou"); //数字按钮的点击事件 function numClk(obj){ span_cumt.innerHTML = span_cumt.innerHTML + obj.value; } //加减乘除按钮的点击事件 function mathClk(obj){ if(span_tai.innerHTML == ""){ span_tai.innerHTML = span_cumt.innerHTML; } span_cumt.innerHTML = ""; span_math.innerHTML = obj.value; span_dengyu.innerHTML = ""; } //等号按钮的点击事件 function resultClk(){ span_hangzhou.innerHTML = span_hangzhou.innerHTML + "<br>" + span_tai.innerHTML + " " + span_math.innerHTML + " " + span_cumt.innerHTML +" = "; var jieguo = eval(span_tai.innerHTML + span_math.innerHTML + span_cumt.innerHTML); span_hangzhou.innerHTML = span_hangzhou.innerHTML + jieguo; span_tai.innerHTML = jieguo; span_cumt.innerHTML = ""; span_math.innerHTML = ""; span_dengyu.innerHTML = "="; } //小数点按钮的点击事件 function writ(){ span_dengyu.innerHTML = ""; span_tai.innerHTML = ""; span_math.innerHTML = ""; span_cumt.innerHTML = ""; span_hangzhou.innerHTML = ""; } </script> </html>

转载于:.html

更多推荐

自己写的一个计算器

本文发布于:2024-02-14 07:42:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1762212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计算器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!