单击相关链接时显示一个 div 并隐藏其他 [英] Show a div when click on related link and hide the others
本文介绍了单击相关链接时显示一个 div 并隐藏其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
<head>
<script>
$(document).ready(function(){
// Optional code to hide all divs
$("div").hide();
// Show chosen div, and hide all others
$("a").click(function ()
{
$("#" + $(this).attr("class")).show().siblings('div').hide();
});
});
</script>
</head>
<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>
我想在点击相关链接时显示一个 div.问题是这个过程只持续几秒钟.有人知道为什么吗?谢谢
I want to display a div when the related link is clicked. The problem is that this process lasts only few seconds. Someone knows why? Thanks
推荐答案
$("a").click(function (e)
{
e.preventDefault();
$("#" + $(this).attr("class")).show().siblings('div').hide();
});
演示 小提琴
这篇关于单击相关链接时显示一个 div 并隐藏其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文