<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		a {
			cursor: pointer;
			color: red;
		}
		#p1, #p2 {
			display: none;
		}
	</style>
</head>
<body>
	<a onclick="con(1)">显示内容1</a>
	<a onclick="con(2)">显示内容2</a>

	<p id="p1">11111</p>
	<p id="p2">22222</p>
	<script>
		flag = "p1";

		function con(i){
			document.getElementById(flag).style.display = "none";
			document.getElementById("p" + i).style.display = "inline";
			flag = "p" + i;
		}
	</script>
</body>
</html>
//参数传递时传递字符串似乎有问题,这里采用的是数字
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐