Html动态点击按钮实现“+”和“-”功能

Html动态点击按钮实现“+”和“-”功能

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html;">
		<title>html动态实现加减</title>
		<style type="text/css">
			.div input{
				width: 40px;
				text-align: center;
			}
		</style>
		<script type="text/javascript">
			function add() {
				var num = document.getElementById("num");
				num.value=parseInt(num.value)+1;
			}
			function minus() {
				var num = document.getElementById("num");
				num.value=parseInt(num.value)-1;
			}
		</script>
	</head>
	<body>
		<div class="div">
			<input type="button"  value="+" onclick="add()" >
			<input type="text"  id="num" value="0">
			<input type="button"  value="-" onclick="minus()">
		</div>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/BlackPlus28/article/details/82532653
今日推荐