HTML, 2 개의 숫자 더하기이다.
<!doctype html>
<html>
<head>
<title>Do Math</title>
</head>
<body>
<h1>Add two numbers</h1>
<h3> Enter 2 numbers in the below boxes to get the sum. </h3>
<input type = "number" id = "my_input1"/>
<input type = "number" id = "my_input2"/>
<input type = "button" value = "Add them Together" onclick = "doMath();"/>
<h2 id="output"></h2>
<script type = "text/javascript">
function doMath() {
var my_input1 = document.getElementById('my_input1').value;
var my_input2 = document.getElementById('my_input2').value;
//Add them Together and Display
var sum = parseFloat(my_input1) + parseFloat(my_input2);
document.getElementById('output').innerHTML = "The sum is " + sum;
}
</script>
</body>
실행결과는 아래와 같다.

'HTML' 카테고리의 다른 글
| Javascript로 2차원 배열 만드는 방법 (0) | 2021.10.10 |
|---|---|
| HTML, 진짜 쉬운 스도쿠 (0) | 2021.09.29 |
| HTML, 타일게임(2048) (0) | 2021.09.28 |
| HTML과 Javascript 로 연립방정식 풀기 (0) | 2021.09.25 |
| HTML, CSS, Javascript로 Todo 앱 만들기 (0) | 2021.09.21 |
댓글