js基础5

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>实现一个简单的加法计算器</title>
	<style type="text/css">
		input{
			width: 50px;
		}
	</style>
	<script type="text/javascript">
		function cal(){
			add1 = Number(document.getElementById("add1").value);//取第一个值
			add2 = Number(document.getElementById("add2").value);//取第二个值
			result = add1+add2;
			document.getElementById("result").value = result;//结果赋值给ID为result的文本框
		}
	</script>
</head>
<body>
	<input id="add1" type="text" name="add1" value=12 /> + 
	<input id="add2" type="text" name="add2" value=14 /> = 
	<input id="result" type="text" name="result">
	<button id="cal" name="cal" onclick="cal()">运算</button>
		
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_43293451/article/details/91378169
js5