JS—点击链接切换隐藏的内容
Documenta {cursor: pointer;color: red;}#p1, #p2 {display: none;}显示内容1显示内容21111122222flag = "p1";function con(i){document.getElementById(flag).style.
·
<!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>
//参数传递时传递字符串似乎有问题,这里采用的是数字更多推荐



所有评论(0)