当焦点上的jquery时,bootstrap工具提示无法正常工作

时间:2013-01-20 13:53:11

标签: jquery twitter-bootstrap checkbox

我想在复选框输入中进行引导,当关注复选框时出现消息。所以这是我做的代码:

HTML

<label class="checkbox inline"><input type="checkbox" class="centang-semua-faktur tooltip-atas" rel="tooltip"> <b>Cetak</b></label>

jquery的

    var $checkAllFaktur = $('.centang-semua-faktur');

    $checkAllFaktur.on('focus', function() {
        if ($(this).is(':checked')){
            $checkAllFaktur.attr('title', 'Hapus Centang Semua').tooltip();  
        }else{
            $checkAllFaktur.attr('title', 'Centang Semua').tooltip();  
        }
    });

请帮帮我。谢谢你:))

1 个答案:

答案 0 :(得分:2)

您的方案中需要showdestroy工具提示,默认情况下,它们只会显示在mouseenter上并隐藏在mouseout上。

您还需要将焦点事件绑定到click事件,以确保在使用鼠标而不仅仅是键盘时获得焦点。

  var $checkAllFaktur = $('.centang-semua-faktur');

$checkAllFaktur
.on('click', function() {
    $(this).trigger('focus')
})
.on('focus', function() {
    if ($(this).is(':checked')){
        $checkAllFaktur.attr('title', 'Hapus Centang Semua').tooltip('show');  
    }else{
        $checkAllFaktur.attr('title', 'Centang Semua').tooltip('show');  
    }
})
.on('blur', function(){
  $(this).tooltip('destroy');
});

工作示例: http://jsfiddle.net/MgcDU/1398/

相关问题