html+js 实现简单的计算器代码 (加减乘除)
<! Doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> </title> </head> <body> <table> <td> <td> <input) 'Adicionar'); "/> </td> <td> <input type =" button "value =" miner "onclick =" Setop ('-', 'miner'); "/> </td> <td> <input type =" button "value =" times "OnClick =" toup ('*', 'times'); ONCLICK = "SETOP ('/', 'DIVIDE');"/> </td> </tr> </tabela> <tabela id = "tb_calc" style = "display: nenhum;"> <tr> <td> <input id = "x" type = "text =" "name =" x "/> </" " </td> <td> <input id = "y" type = "text" value = "" name = "y"/> </td> <td> <input id = "optips" type = "button" value = "" onclick = "calc ();"/> </td> <td> <lable id = "z" name = = = "" type = "Application/javaScript"> function setop (op, optips) {var tb = document.getElementById ("tb_calc"); tb.style.display = "nenhum"; 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 = "bloco"; } função calc () {var x = parseint (document.getElementById ("x"). valor); var y = parseint (document.getElementById ("y"). valor); var op = document.getElementById ("op"). InnerText; var z = ""; switch (op) {case ' +': z = x + y; quebrar; case ' -': z = x - y; quebrar; caso '*': ; z = x * y; quebrar; caso '/': ; z = x / y; quebrar; padrão: z = ''; } console.log (x, op, y, '=', z); document.getElementById ("Z"). InnerText = z; } </script> </body> </html>截图如下
以上这篇 html+js 实现简单的计算器代码 (加减乘除) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。