如何在禁用按钮上启用bootstrap工具提示? [英] How to enable bootstrap tooltip on disabled button?
本文介绍了如何在禁用按钮上启用bootstrap工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在禁用按钮上显示工具提示,并在启用按钮上将其删除。
实际上它以相反的方式工作。
I need to display a tooltip on disabled button and remove it on enabled button. Actually it works in reverse way.
反转此行为的最佳方法是什么?
What is the best way to invert this behaviour?
$('[rel=tooltip]').tooltip();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<hr>
<button class="btn" disabled rel="tooltip" data-title="Dieser Link führt zu Google">button disabled</button>
<button class="btn" rel="tooltip" data-title="Dieser Link führt zu Google">button not disabled</button>
以下是演示: http:// jsfiddle.net/BA4zM/68/
PS:我想保持属性被禁用。
P.S.: I want to keep the attribute disabled.
推荐答案
以下是一些工作代码: http://jsfiddle.net/mihaifm/W7XNU/200/
Here is some working code: http://jsfiddle.net/mihaifm/W7XNU/200/
$('body').tooltip({
selector: '[rel="tooltip"]'
});
$(".btn").click(function(e) {
if (! $(this).hasClass("disabled"))
{
$(".disabled").removeClass("disabled").attr("rel", null);
$(this).addClass("disabled").attr("rel", "tooltip");
}
});
想法是使用选择器<将工具提示添加到父元素/ code>选项,然后在启用/禁用按钮时添加/删除
rel
属性。
这篇关于如何在禁用按钮上启用bootstrap工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文