추가, 뺄셈, 곱셈 및 자바 스크립트의 간단한 예
<html> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"/> </head> <script ancouant = "javaScript"type = "text/javaScript"> // divide function accdiv (arg1, arg2) {var t1 = 0, t2 = 0, r1, r1, r2, n; {t1 = arg1.tostring (). split ( ".") [1] .length; } catch (e) {t1 = 0;} try {t2 = arg2.toString (). split ( ".") [1] .length; } catch (e) {t2 = 0;} with (math) {r1 = number (arg1.toString (). replace ( ".", ")); r2 = number (arg2.toString (). 교체 (". ","); n = math.max (t1, t2); 반환 (R1/R2)*Pow (10, T2-T1); }} // 다중 함수 accmul (arg1, arg2) {var t1 = 0, t2 = 0, r1, r2; {t1 = arg1.tostring (). split ( ".") [1] .length; } catch (e) {t1 = 0;} try {t2 = arg2.toString (). split ( ".") [1] .length; } catch (e) {t2 = 0;} with (math) {r1 = number (arg1.toString (). replace ( ".", ")); r2 = number (arg2.toString (). 교체 (". ","); return (r1*r2)/pow (10, t2+t1); }} // 함수 추가 accadd (arg1, arg2) {var t1 = 0, t2 = 0, m; {t1 = arg1.tostring (). split ( ".") [1] .length; } catch (e) {t1 = 0;} try {t2 = arg2.toString (). split ( ".") [1] .length; } catch (e) {t2 = 0;} with (math) {m = math.pow (10, math.max (t1, t2)); return (arg1 * m + arg2 * m) / m; }} // 뺄셈 함수 accsubtr (arg1, arg2) {var t1 = 0, t2 = 0, m, n; {t1 = arg1.tostring (). split ( ".") [1] .length; } catch (e) {t1 = 0;} try {t2 = arg2.toString (). split ( ".") [1] .length; } catch (e) {t2 = 0;} with (math) {// 동적 제어 정밀 길이 n = math.max (t1, t2); m = math.pow (10, n); // return (arg1 * m -arg2 * m) /m; return ((arg1 * m -arg2 * m) / m) .tofixed (n); }} // 문자열 유형에 div 메소드를 추가하여 호출하는 것이 더 편리합니다. string.prototype.div = function (arg) {return accdiv (this, arg);} // 문자열 유형에 MUL 메소드를 추가하여 호출하는 것이 더 편리합니다. string.prototype.mul = function (arg) {return accmul (arg, this);} // 문자열 유형에 추가 메소드를 추가하여 호출하는 것이 더 편리합니다. string.prototype.add = function (arg) {return accadd (arg, this);} // 문자열 유형에 서브트 메소드를 추가하여 호출하는 것이 더 편리합니다. string.prototype.subtr = function (arg) {return acsubtr (this, arg);} 함수 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 id = "form1"form1 "name ="form1 "method ="post "runat ="server "> <div style ="테두리 : solid 1px #0000 #0000; type = "text"value = "0"name = "textbox1" /< /div> <div style = "float : 왼쪽; 왼쪽; 너비 : 30%;"> <입력 ID = "textbox2"value = "0"type = "text"name = "textbox2" /> < /div> <div style = "float : width : 30%;"> accdiv : <text id = "texpbox 5" "" 이름 = "textbox5" /> < /div> <div> accmul : <input id = "textbox6"type = "text"name = "textbox6" /< /div> <div> accadd : <input id = "textbox7"type = "text"name = "textbox7" /> < /div> <div> accsubtr : <text8 ""textbox " /> </div> </div> <div style = "float : 오른쪽; 너비; 너비 : 10%;"> <input type = "button"name = "aa"value = "cal"onclick = "cal ();"; /> </div> </div> </form> </body> </html>위의 간단한 추가 예제, 뺄셈, 곱셈 및 JavaScript의 구분은 내가 공유하는 모든 내용입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.