足し算計算機
入力欄2つ、ボタンクリックで足し算という、簡単なプログラムです。
デモ
プログラム
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>足し算計算機</title>
<script>
window.onload = function() {
function tasu() {
var x = parseInt(document.getElementById('c1').value, 10);
var y = parseInt(document.getElementById('c2').value, 10);
document.getElementById('c3').value = x + y;
}
document.getElementById('a').addEventListener('click', tasu);
}
</script>
</head>
<body>
<form name="form1">
<input type="text" id="c1">
+
<input type="text" id="c2">
=
<button type="button" id="a">足す</button>
<input type="text" id="c3">
</form>
</body>
</html>
解説
(追記予定)