【发布时间】:2019-06-26 05:25:36
【问题描述】:
您能否运行以下 html 测试用例,以帮助确定当工具提示位于按钮上方时按钮被禁用时如何使 bootstrap 4 工具提示消失?代码中列出了有关我的问题的详细信息。
stackoverflow 编辑器不满意我将细节作为 cmets 放入代码中,因此我将在此重复一些细节以尝试让编辑器满意。当光标悬停在按钮上时禁用按钮时,工具提示不会消失,而且看起来很糟糕。任何帮助表示赞赏。
谢谢
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4 Tooltip Persists, Looks Terrible</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Bootstrap 4 Tooltip Persists, Looks Terrible</h3>
<br> "Other button disabled" scenario works fine.
<br> First, hover over buttons. Look at tooltips while hovering.
<br> Then, click button A to disable button B. Works fine:
<br> - Button B is disabled, and no tooltip.
<br> - Tooltip still works correctly on button A.
<br> <br>
<button type="button" id="button_a" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" title="Disables Button B" onclick='change_button ("button_b", true);'>
Button A
</button>
<button type="button" id="button_b" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" title="Disabled by Button A">
Button B
</button>
<br> <br> <hr>
<br> "Same button disabled" scenario fails.
<br> First, hover over Button C. Look at the tooltip.
<br> Then, click button C to disable button C. Messes up:
<br> - Button C is disabled, so that part is OK.
<br> - But Button C tooltip persists, looks terrible.
<br> <br>
<button type="button" id="button_c" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" title="Disables Button C" onclick='change_button ("button_c", true);'>
Button C
</button>
<button type="button" id="button_d" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" title="Enables Button C" onclick='change_button ("button_c", false);'>
Button D
</button>
<br> <br> <hr> <br>
So if a button is disabled while the cursor is hovering over it, the tooltip persists.
<strong>
Could you please explain how to make tooltip go away when Button C is disabled?
</strong>
I would prefer if tooltip went away when Button C disabled,
since that is default behavior of bootstrap disabled buttons.
And disabled button may later get enabled again, so I do not want to delete title attribute.
Basically I want bootstrap to behave the same way as when Button B is disabled.
I have looked around and cannot find how to fix this problem,
and have tried various things, with no success.
There are real instances where a button carries out an action,
and then the button needs to be disabled, so I appreciate the help. Thanks
</div>
<script>
$(document).ready(function(){$('[data-toggle="tooltip"]').tooltip();});
function change_button (button_id, bool_val) {
var button_obj = document.getElementById (button_id);
button_obj.disabled = bool_val;
}
</script>
</body>
</html>
【问题讨论】:
标签: jquery css twitter-bootstrap bootstrap-4