本文转自:http://*.com/questions/19132970/hide-or-remove-jquery-ui-tab-based-on-condition
问:
Html:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab1</a></li>
<li><a href="#tabs-2">Tab2</a></li>
<li><a href="#tabs-3">Tab3</a></li>
</ul>
<div id="tabs-1">
Tab1 Contain
</div>
<div id="tabs-2">
Tab2 Contain
</div>
<div id="tabs-3">
tab3 contain
</div>
</div>
What I try on js :
var id="A";
$( "#tabs" ).tabs();
if(id==="A")
{
$( "#tabs-2" ).tabs( "option", "hide", { effect: "explode", duration: 1000 } );
//$('#ui-id-2').hide();
}
Sample Fiddle.
I want to hide or remove particular tab if condition is met.Thanks.
答:
Try
var id = "A";
$("#tabs").tabs();
if (id === "A") {
$('#tabs > ul li:has(a[href="#tabs-1"])').hide()
$("#tabs").tabs('refresh');
$("#tabs").tabs('option', 'active', 1);
}
Demo: Fiddle