이 기사의 방법은 매우 간단하며 아이디어는 추천 할 가치가 있습니다. 참조하십시오.
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = utf-8" />
<title> JavaScript 간단한 계산기 </title>
<cript>
// 글로벌 변수 정의 var one = "1";
var two = "2";
var Three = "3";
var 4 = "4";
var 5 = "5";
var Six = "6";
var 7 = "7";
var 8 = "8";
var nine = "9";
var Zero = "0";
var plus = "+", minus = "-", multiply = "*", divide = "/", Decimal = ";";
함수 Enter (obj, String) {
obj.expr.value+= 문자열;
}
함수 compute (obj) {// 호출 할 "="버튼과 동일한 함수를 클릭합니다. obj.expr.value = Eval (obj.expr.value); // js를 사용하여 evpr}의 공식으로 이름을 계산하기 위해 eval () 메소드를 얻습니다.
</스크립트>
</head>
<body>
<form name = "calc"id = "calc"action = "">
<테이블>
<td colspan = "4"> <입력 유형 = "text"name = "expr"size = "30"action = "compute (this.form)" /> < /td>
<tr>
<td> <입력 유형 = "버튼"value = "7"onclick = "enth (this.form, 7)" /> < /td>
<td> <입력 유형 = "버튼"value = "8"onclick = "enth (this.form, 8)" /> < /td>
<td> <입력 유형 = "버튼"value = "9"onclick = "enth (this.form, nine)" /> < /td>
<td> <입력 유형 = "버튼"value = " /"onclick = "enth (this.form, divide)" /> < /td>
</tr>
<tr>
<td> <입력 유형 = "버튼"value = "4"onclick = "enth (this.form, four)" /> < /td>
<td> <입력 유형 = "버튼"value = "5"onclick = "enth (this.form, 5)" /> < /td>
<td> <입력 유형 = "버튼"value = "6"onclick = "enth (this.form, six)" /> < /td>
<td> <input type = "button"value = " *"onclick = "enth (this.form, 곱하기)" /> < /td>
</tr>
<tr>
<td> <입력 유형 = "버튼"value = "1"onclick = "enth (this.form, one)" /> < /td>
<td> <입력 유형 = "버튼"value = "2"onclick = "enth (this.form, two)" /> < /td>
<td> <input type = "button"value = "3"onclick = "enth (this.form, 3)" /> < /td>
<td> <입력 유형 = "버튼"value = " -"onclick = "enth (this.form, minus)" /> < /td>
</tr>
<tr>
<td colspan = "2"> <입력 유형 = "버튼"value = "0"onclick = "enth (this.form, zero)" /> < /td>
<td> <입력 유형 = "버튼"value = "
<td> <입력 유형 = "버튼"value = " +"onclick = "enth (this.form, plus)" /> < /td>
</tr>
<tr>
<td colspan = "2"> <입력 유형 = "버튼"value = "="onclick = "compute (this.form)" /> < /td>
<td colspan = "2"> <입력 유형 = "버튼"value = "ac"onclick = "form.reset ()"/> </td>
</tr>
</테이블>
</form>
</body>
</html>
슈퍼 NB 코드, 마스터 레벨입니까!