单击特定选项卡时,如何隐藏在手风琴菜单项中打开的所有选项卡?

ASR

我有一个要求,当我单击任何选项卡时,它都像手风琴菜单选项卡一样工作,但是这里的一个问题是,当我单击任何其他选项卡时,应该关闭打开的选项卡,而只有与选项卡相关的当前内容才应显示为html。我提到的只是示例,实际上id和div是动态生成的。我还要插入图片以便更好地理解。在此处输入图片说明

<script	src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"/>
<script>
	$(document).ready(function(){
		

	// Get all the links.
	var link = $("#vy_accordion a");
	

	// On clicking of the links do something.
	link.on('click', function(e) {

	    e.preventDefault();

	    var a = $(this).attr("href");

	    $(a).slideToggle('fast');
	    
	    $(".control-group").css({ 'display' : 'block', 'margin-bottom' : '0' });

	    
	});
	
	});
	
	</script>
#vy_accordion {
	margin-top: 10px;
	border: thin solid #cecece;
	border-top: none;
	border-bottom: none;
}

#vy_accordion div {
	background: white;
	/*height: inherit;
	line-height: inherit;*/
	display: none;
	border-bottom: thin solid #cecece;
	padding-left: 15px;
	min-height: 70px;
}

a.divlink {
	display: block;
	/* width: 483px; */
	background: #f4f4f4;
	background-image: -webkit-linear-gradient(white, #ededed);
	background-image: -moz-linear-gradient(white, #ededed);
	background-image: -o-linear-gradient(white, #ededed);
	background-image: -ms-linear-gradient(white, #ededed);
	background-image: linear-gradient(white, #ededed);
	color: #959696;
	padding-left: 15px;
	height: 40px;
	line-height: 40px;
	text-decoration: none;
	border-bottom: thin solid #cecece;
	border-top: thin solid #cecece;
	font-family: Arial;
	font-size: 13px;
	font-weight: bold;
	text-shadow: 0px 1px 1px white;
}
<a class="divlink" href="#Menu-hover-color">Menu-hover-color</a>
<div id="Menu-hover-color" style="display: none;"> 
  <div class="control-group"> 
    <label class="control-label" for="_156_Menu-hover-color"> Menu-hover-color </label> <input class="field" id="_156_Menu-hover-color" name="" type="text" value="#B3E5FC">  
  </div> 
</div>
<a class="divlink" href="#Menu-hover-color">Menu-item-color</a>
<div id="Menu-item-color" style="display: none;"> 
  <div class="control-group"> 
    <label class="control-label" for="_156_Menu-item-color"> Menu-hover-color </label> <input class="field" id="_156_Menu-item-color" name="" type="text" value="#B3E5FC">  
  </div> 
</div>

帕卡什·库玛(Parkash Kumar)

在显示被单击/选定的选项卡之前linkTab,根据此类选择器调用hide()将类似的类添加到您的选项卡(例如,如下所示:

HTML:

<a class="divlink" href="#Menu-hover-color">Menu-hover-color</a>
    <div class="linkTab" id="Menu-hover-color" style="display: none;">
...

JS:

var link = $("#vy_accordion a");

// On clicking of the links do something.
link.on('click', function(e) {
    e.preventDefault();

    var a = $(this).attr("href");

    // this line will hide all open tab based on class selector
    $('.linkTab').hide();

    $(a).slideToggle('fast');

    $(".control-group").css({ 'display' : 'block', 'margin-bottom' : '0' });

});

演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

单击时关闭手风琴选项卡

保持手风琴菜单的所有选项卡关闭

如何在特定选项卡、选项卡式活动、Kotlin 中隐藏菜单项

根据html和javascript中的手风琴选项卡的单击显示特定内容

Bootstrap手风琴选项卡未打开

如何在此手风琴中打开默认选项卡,并在打开另一个选项卡时将其关闭?

jQuery手风琴显示特定选项卡

jQuery手风琴-如何首先关闭所有选项卡

第一次单击后手风琴选项卡不打开

为什么单击我的手风琴时不显示子选项卡?

如何一次打开一个手风琴选项卡

jQuery UI-使用外部链接在选项卡中打开手风琴

Bootstrap手风琴选项卡不折叠

右键单击“ Ant Design的折叠菜单项”,不会显示“在新选项卡中打开”

可访问的手风琴角色(选项卡和选项卡列表)

可见,哪个“手风琴”选项卡已打开

Javascript手风琴折叠在新选项卡上打开

使用带有复选框的纯 css 手风琴,您可以打开和关闭所有打开的选项卡吗?

flex 4如何实现可打开多个选项卡的自定义手风琴

jQuery手风琴选项卡没有关闭

在primefaces的新选项卡中打开菜单项页面

如何在单个选项卡菜单(ALL)中显示所有选项卡内容?

Bootstrap 4获取导航选项卡与卡片手风琴合拢

双重嵌套视图:UI-Router或UI-Bootstrap选项卡/手风琴?

使用选项卡和手风琴显示结果

jQuery更新后激活选项卡和手风琴

在选项卡中使用两个Bootstrap手风琴

JavaFX 手风琴在选项卡平移时不会折叠

如何在React的每个关闭的手风琴选项卡的顶部动画中添加滚动条?