0

我使用引導程序3並具有按鈕和輸入。如果按鈕被禁用,我想顯示工具提示,如果提交按鈕的類型,則隱藏工具提示。在我的代碼段.tooltip('hide')方法不起作用,我不知道爲什麼。工具提示隱藏/顯示在引導程序中不起作用

jsfiddle

HTML

<div class=" user-attributes"> 
<input type="text" name="attrName" /> 

    <button type="submit" data-toggle="tooltip" title="Please select attribute name" class="btn btn-default disabled" name="addAttribute" >Add attribute</button> 

    </div> 

的JavaScript

$('button[data-toggle="tooltip"]').tooltip({ 
    animated: 'fade', 
    placement: 'bottom', 
}); 
/* allow bootstrap tooltip for disabled buttons */ 
$('.user-attributes button[type="submit"]').css('pointer-events', 'auto'); 

$(".user-attributes [name='attrName']").bind('input', function(){ 
    var inputIsEmpty = $(this).val().length < 1; 
    if (inputIsEmpty){ 
     $('.user-attributes button[type="submit"]').addClass('disabled'); 
     $('.user-attributes button[type="submit"]').removeAttr('type'); 
     $('.user-attributes button[type="submit"]').css('pointer-events', 'auto'); 
     $('button[data-toggle="tooltip"]').tooltip('show'); 
    } else { 
     $('.user-attributes button[type="submit"]').removeClass('disabled'); 
     $('.user-attributes button[type="submit"]').removeAttr('style'); 
     $('.user-attributes button[type="submit"]').attr('type', 'submit'); 
     $('button[data-toggle="tooltip"]').tooltip('hide'); 
    } 

}); 

回答