gpt4 book ai didi

jquery - 使用单独的按钮打开/关闭 Div

转载 作者:行者123 更新时间:2023-11-28 11:10:00 25 4
gpt4 key购买 nike

我正在尝试使用图像作为按钮来显示 div 容器上的内容,就像 youtube 上顶部和左侧的按钮一样。

我想连续做几个按钮,让它们在另一个div上显示某个内容。因为每个按钮的所有内容都显示在同一个 div 中,所以我希望打开的内容在单击另一个按钮时消失。我知道 JQuery 的 tabs() 函数,但我还没有找到任何带有分离按钮的解决方案。

编辑:对我有用的代码,但没有单独的按钮(我想要的)

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Tabs - Default functionality</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(function() {
$( "#tabs" ).tabs( );
});
</script>
<style type="text/css">
#tabs {width:100%;height:100%;}

ul {clear:both; background:black;}

li .active {float:left;}

li {display:none;}
</style>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tab-1">Nunc tincidunt</a></li>
<li><a href="#tab-2">Proin dolor</a></li>
<li><a href="#tab-3">Aenean lacinia</a></li>
</ul>
<div id="tab-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tab-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tab-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>
</body>
</html>

最佳答案

这是FIDDLE吗?像你想要的东西?

JS

$('.text').hide();

$('img').click(function(){
if ( $(this).attr('id') == 'phooey' )
{
$('.holder1').children('.text').toggle('slide');
}
if ( $(this).attr('id') == 'dawg' )
{
$('.holder2').children('.text').toggle('slide');
}
if ( $(this).attr('id') == 'woody' )
{
$('.holder3').children('.text').toggle('slide');
}

});

编辑:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

关于jquery - 使用单独的按钮打开/关闭 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22055204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com