那么我是新来的HTML/JS脚本,但我正在一个项目,我想用超链接来显示/隐藏div 例如,如果我点击第一个超链接,它应该显示div id:1只,如果我点击第二个超链接,它应该只显示2nd div。 我设法找到了什么,我需要互联网上的例子,但我不知道,为什么不管我尝试它亘古不变的工作对我来说将html包含到html页面
an example of what i need - my fiddle
,这是我的代码
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top:20px;
}
</style>
</head>
<body>
<body>
Click a button to make it visible:<br /><br />
<a href="#" class="one">One</a>
<a href="#" class="two">Two</a>
<a href="#" class="three">Three</a>
<a href="#" class="four">Four</a><br /><br />
<div id="one">One</div>
<div id="two">Two</div>
<div id="three">Three</div>
<div id="four">Four</div><br/><br/>
</body>
<script>
$("div").hide();
// Show chosen div, and hide all others
$("a").click(function (e)
{
//e.preventDefault();
$("#" + $(this).attr("class")).show().siblings('div').hide();
});
</script>
</body>
</html>
以及..你缺少的jquery.js补充一点: –
它对我工作JSFIDDLE在本地项目上添加jQuery库 –
您还可以使用'jquery tabs':https://jqueryui.com/tabs/ –