Javascript使用JQuery隐藏/显示选项卡
我有一个关于如何使用jQuery选项卡的快速问题(单击链接按钮以显示/隐藏某些div)。div id与链接的href匹配: HTML链接:Javascript使用JQuery隐藏/显示选项卡,javascript,jquery,tabs,html-table,show-hide,Javascript,Jquery,Tabs,Html Table,Show Hide,我有一个关于如何使用jQuery选项卡的快速问题(单击链接按钮以显示/隐藏某些div)。div id与链接的href匹配: HTML链接: 需要显示/隐藏的div: <div id="site"> <table class='explore'> <thead class='ui-widget-header'> <tr> <th class=' sortable'> Sit
需要显示/隐藏的div:
<div id="site">
<table class='explore'>
<thead class='ui-widget-header'>
<tr>
<th class=' sortable'>
Site
</th>
<th class=' sortable'>
Number
</th>
</tr>
</thead>
</table>
</div>
场地
数
这会完全满足你的要求。但是,我怀疑当显示一个div时,您还想隐藏所有其他div。是吗
好的,既然你已经回答说这是真的,这是你的新代码。
您还应该在所有div中添加一个类(在我的代码中是“tabdiv”),以便它们可以一起轻松选择
$("table.tabs a").click( function() {
var id = $(this).attr( "href" );
// Hide all the tab divs
$(".tab-div").hide();
// Then show the one that's been clicked
$(id).show();
} );
好吧,如果你这样做了,你应该在你最初的问题中问这个问题,不是吗?我已经编辑了答案。仅供参考。在第一个示例中,可以将代码“if(div.is(“:visible”))div.hide();else div.show();”修改为div.toggle()@谢谢,我不知道。更正。
$("table.tabs a").click( function() {
var id = $(this).attr( "href" );
var div = $(id);
div.toggle();
} );
$("table.tabs a").click( function() {
var id = $(this).attr( "href" );
// Hide all the tab divs
$(".tab-div").hide();
// Then show the one that's been clicked
$(id).show();
} );