Exemplo simples de adição, subtração, multiplicação e divisão em JavaScript
<html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> </ad head> <script linguy = "javascript" type = "text/javascript"> // divide funcdiv (arg1, arg2) {var t1/ tente {t1 = arg1.toString (). Split (".") [1] .Length; } catch (e) {t1 = 0;} tente {t2 = arg2.toString (). split (".") [1] .Length; } catch (e) {t2 = 0;} com (math) {r1 = número (arg1.toString (). substituir (".", ","); r2 = número (arg2.toString (). substituir (".", ""); n = math.max (t1, t2); return (r1/r2)*pow (10, t2-t1); }} // Função múltipla accmul (arg1, arg2) {var t1 = 0, t2 = 0, r1, r2; tente {t1 = arg1.toString (). Split (".") [1] .Length; } catch (e) {t1 = 0;} tente {t2 = arg2.toString (). split (".") [1] .Length; } catch (e) {t2 = 0;} com (math) {r1 = número (arg1.toString (). substituir (".", ","); r2 = número (arg2.toString (). substituir (".", ""); return (r1*r2)/pow (10, t2+t1); }} // Adicionar função accadd (arg1, arg2) {var t1 = 0, t2 = 0, m; tente {t1 = arg1.toString (). Split (".") [1] .Length; } catch (e) {t1 = 0;} tente {t2 = arg2.toString (). split (".") [1] .Length; } catch (e) {t2 = 0;} com (math) {m = math.pow (10, math.max (t1, t2)); return (arg1 * m + arg2 * m) / m; }} // função de subtração accsubtr (arg1, arg2) {var t1 = 0, t2 = 0, m, n; tente {t1 = arg1.toString (). Split (".") [1] .Length; } catch (e) {t1 = 0;} tente {t2 = arg2.toString (). split (".") [1] .Length; } catch (e) {t2 = 0;} com (math) {// Comprimento de precisão de controle dinâmico n = math.max (t1, t2); m = math.pow (10, n); // return (arg1 * m - arg2 * m) /m; return ((arg1 * m - arg2 * m) / m) .tofixado (n); }} // Adicione um método div ao tipo String, que é mais conveniente para ligar. String.prototype.div = function (arg) {return accdiv (this, arg);} // Adicione um método mul ao tipo de string, tornando mais conveniente ligar. String.prototype.mul = function (arg) {return accmul (arg, this);} // Adicione um método Adicionar ao tipo de string, tornando mais conveniente ligar. String.prototype.add = function (arg) {return accadd (arg, this);} // Adicione um método subtr ao tipo de string, tornando mais conveniente ligar. String.prototype.subtr = function (arg) {return acsubtr (this, arg);} função cal () {var arg1 = document.form1.textbox1.value; var arg2 = document.form1.textbox2.value; //document.form1.textbox5.Value = accdiv (arg1, arg2); //document.form1.textbox6.value = accmul (arg1, arg2); //document.form1.textbox7.value = accadd (arg1, arg2); //document.form1.textbox8.value = accsubtr (arg1, arg2); document.form1.textbox5.value = arg1.div (arg2); document.form1.textbox6.value = arg1.mul (arg2); document.form1.textbox7.value = arg1.add (arg2); document.form1.textbox8.value = arg1.subtr (arg2);} </script> <body> <form od = "form1" name = "form1" method = "post" runat = "servidor"> <div estilo = "borda: sólido 1px #000000; width: 600px;"> <div estilo = "" type = "text" value = "0" name = "textbox1" /> </div> <div style = "float: esquerda; largura: 30%;"> <input id = "textbox2" value = "0" type = "text" name = "textbox2" /> < /div> <style = "float: esquerda; width: 30%">>> name = "textbox5" /> </div> <div> accmul: <input id = "textbox6" type = "text" name = "textbox6" /> < /div> <div> accadd: <input id = "textbox7" type = "text" name = "textbox7" /> < /div <div> <div> /> </div> </div> <div style = "float: direita; largura: 10%;"> <input type = "button" name = "aa" value = "cal" onclick = "cal ();" /> </div> </div> </morm> </body> </html>O exemplo simples acima de adição, subtração, multiplicação e divisão do JavaScript é todo o conteúdo que compartilho com você. Espero que você possa lhe dar uma referência e espero que você possa apoiar mais o wulin.com.