<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<head>
</head>
<body>
<!--기호는 ''-->
입력칸1: <input type="text" id="num1" name="numA"><br>
입력칸2: <input type="text" id="num2" name="numB"><br>
<button id="plus" onclick="calcu('+')">+</button>
<button id="minus" onclick="calcu('-')">-</button>
<button id="multiply" onclick="calcu('*')">*</button>
<button id="divide" onclick="calcu('/')">/</button>
결과값: <input type="text" id="result" name="result"><br>
<script type="text/javascript">
function calcu(n) {
var number1 = parseFloat(document.getElementById("num1").value);
var number2 = parseFloat(document.getElementById("num2").value);
var resulttext = 0;
switch(n){
case "+": resulttext= number1 + number2; break;
case "-": resulttext= number1 - number2; break;
case "*": resulttext= number1 * number2; break;
case "/": resulttext= number1 / number2; break;
}
document.getElementById("result").value = resulttext;
}
</script>
</body>
</html>
'단순 코드 기록 > JAVA' 카테고리의 다른 글
Java_Event (0) | 2024.02.10 |
---|---|
Java_order (0) | 2024.02.10 |
Java_Link (0) | 2024.02.10 |
Java_OpenWindow (0) | 2024.02.10 |
Java_Date (0) | 2024.02.10 |