html+js 实现简单的计算器代码 (加减乘除)
<! Doctype html> <html> <head> <meta http-equiv = "konten-tipe" content = "text/html; charset = utf-8"/> <itement> </itement> </head> <body> <ablick> <tr> <td> <input type = "Tombol" value = "add"; <td><input type="button" value="miner" onclick="setOp('-', 'miner');"/></td> <td><input type="button" value="times" onclick="setOp('*', 'times');"/></td> <td><input type="button" value="divide" onclick="setOp('/', 'Divide'); "/> </td> </tr> </able> <table id =" tb_calc "style =" display: none; "> <tr> <td> <input id =" x "type =" text "value =" "name =" x "/> </td> <td> <lable id =" op "name =" x "/> </td> <td> <lable id id =" op "name" name " id="y" type="text" value="" name="y" /> </td> <td> <input id="opTips" type="button" value="" onclick="calc();"/> </td> <td> <lable id="z" name="z"></lable> </td> </tr></table><script type="application/javascript"> function setop (op, opts) {var tb = document.geteLementById ("tb_calc"); tb.style.display = "none"; document.geteLementById ("x"). value = ""; document.geteLementById ("y"). value = ""; document.geteLementById ("z"). Innertext = ""; document.geteLementById ("op"). Innertext = op; document.geteLementById ("Optips"). Value = Optips; tb.style.display = "block"; } function calc () {var x = parseInt (document.geteLementById ("x"). value); var y = parseInt (document.getElementById ("y"). value); var op = document.getElementById ("op"). Innertext; var z = ""; switch (op) {case ' +': z = x + y; merusak; case ' -': z = x - y; merusak; kasus '*': ; z = x * y; merusak; kasus '/': ; z = x / y; merusak; Default: z = ''; } console.log (x, op, y, '=', z); document.getElementById ("z"). Innertext = z; } </script> </body> </html>截图如下 :
以上这篇 html+js 实现简单的计算器代码 (加减乘除) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。