반응형

1. HTML문서와 JavaScript 문서로 분할

2. JavaScript 정의

function multi(){
		var firstNum = document.forms[0].firstnumber.value;
		var secondNum = document.forms[0].secondnumber.value;
				
		var multiValue = firstNum * secondNum;
		document.forms[0].value.setAttribute('value',multiValue);
}

3. HTML 정의

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>HTML과 JavaScript</title>
		<link rel = "stylesheet" href = "css/style.css">
		<script src = "script.js"></script>
	</head>
	<body>
		<h3>곱셈 계산기</h3>
		<form>
			<input type = "number" name ="firstnumber" value = "0">x
			<input type = "number" name ="secondnumber" value = "0">=
			<input type = "text" name ="value">
			<input type = "button"  value = "계산하기" onClick = "multi()">
		</form>
	</body>
</html>

4. 실행

반응형

+ Recent posts