html+js 实现简单的计算器代码 (加减乘除)
<! Doctype html> <html> <fead> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> </title> </toad> <body> <bodel> <tr> <td> <input type = "bootle" value = "add" oncLick = "setop ('+',, 'add'); "/> </td> <td> <input type =" button "value =" miner "onClick =" setop ('-', 'miner'); "/> </td> <td> <input type =" button "value =" times "en ondclick =" setop ('*', 'Times'); "/> </td> <td> <type de input type" onClick = "setop ('/', 'divide');"/> </td> </tr> </topla> <table id = "tb_calc" style = "visual <TD> <input id = "y" type = "text" value = "" name = "y"/> </td> <td> <input id = "optips" type = "button" value = "" onClick = "calc ();"/> </td> <td> <td> <lable id = "z" name = "z"> </lable> </td> </tr> </tabret> type = "Application/JavaScript"> function setop (op, optips) {var tb = document.getElementById ("tb_calc"); tb.style.display = "Ninguno"; document.getElementById ("x"). valor = ""; document.getElementById ("y"). valor = ""; document.getElementById ("Z"). Innertext = ""; document.getElementById ("op"). inntext = op; document.getElementById ("optips"). valor = optips; tb.style.display = "bloque"; } function 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; romper; caso ' -': z = x - y; romper; caso '*': ; z = x * y; romper; caso '/': ; z = x / y; romper; predeterminado: z = ''; } console.log (x, op, y, '=', z); document.getElementById ("Z"). Innertext = Z; } </script> </body> </html>截图如下 :
以上这篇 html+js 实现简单的计算器代码 (加减乘除) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 也希望大家多多支持武林网。 也希望大家多多支持武林网。