工具提示隐藏/显示在引导中不起作用

Tooltip hide/show doesn't work in Bootstrap

本文关键字:不起作用 隐藏 显示 工具提示      更新时间:2023-09-26

我使用bootstrap 3,并有一个按钮和输入。我想显示工具提示,如果按钮被禁用,隐藏工具提示,如果按钮的类型是提交。在我的代码片段.tooltip('hide')方法不工作,我不知道为什么。

jsfiddle

    <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');
    }
});

.tooltip('destroy');帮助。

jsfiddle