2016-12-03 59 views
0

我需要在加載頁面時禁用我的標籤之一。 用戶選擇一個iten後,必須啓用該選項卡並模擬點擊它。 禁用的情況下這是爲我工作,但是當我刪除禁用類,我的「禮」在這個選項卡中單擊事件什麼也不做......Bootstrap導航標籤已禁用並啓用

<ul id="tab-principal" class="nav nav-tabs nav-justified" role="tablist"> 
 
    <li class="active" id="navPesquisa"><a data-target="#divPesquisa" data-toggle="tab">Pesquisa</a></li> 
 
    <li role="presentation" id="navDadosDocumento"><a href="#divDetalhes" aria-controls="divDetalhes" role="tab" data-toggle="tab">Dados do Documento</a></li> 
 
</ul>

禁用標籤

// Desabilita a aba de dados do aço interno 
 
$('#navDadosDocumento').attr('class', 'disabled');

啓用和CLIC K的標籤

$('#navDadosDocumento').removeAttr('class', 'disabled'); 
 
$('a[href="#divDetalhes"]').trigger('click');

回答

0

嘗試這樣的事情。

$(document).ready(function() { 
    $('#navDadosDocumento').attr('class', 'disabled'); 
    }); 
    $("#divDetalhes").click(function() { 
    $('#navDadosDocumento').removeAttr('class', 'disabled'); 
    $('a[href="#divDetalhes"]').trigger('click'); 
    }); 

也檢查這裏

$(document).ready(function() { 
 
    $('#navDadosDocumento').attr('class', 'disabled'); 
 
}); 
 
$("#divDetalhes").click(function() { 
 
    $('#navDadosDocumento').removeAttr('class', 'disabled'); 
 
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 

 
    <!-- jQuery library --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 

 
    <!-- Latest compiled JavaScript --> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
<ul id="tab-principal" class="nav nav-tabs nav-justified" role="tablist"> 
 
    <li class="active" id="navPesquisa"><a data-target="#divPesquisa" data-toggle="tab">Pesquisa</a></li> 
 
    <li role="presentation" id="navDadosDocumento"><a href="#divDetalhes" aria-controls="divDetalhes" role="tab" data-toggle="tab">Dados do Documento</a></li> 
 
</ul>

+0

抱歉,但我不明白...當用戶點擊時,我會啓用選項卡嗎?它在? –

1

.removeAttr()僅採用一個參數,要移除的屬性。 添加和刪除類,jQuery提供.addClass().removeClass()方法

編號:https://api.jquery.com/removeAttr/ https://api.jquery.com/removeClass/

因此,爲了使你的代碼的工作,取代

$('#navDadosDocumento').removeAttr('class', 'disabled'); 

$('#navDadosDocumento').removeClass('disabled');