我有一个简单的引导工具提示按钮,当我将鼠标悬停时应该显示一个工具提示,但是它不起作用。我在网上遵循了许多有关在文档加载时初始化工具提示的建议,但仍然无法使用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../style.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<title>Parent View</title>
</head>
<body>
<div class="container mt-5">
<button type="button" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="">
Tooltip on top
</button>
<script type="text/javascript">
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:2)
当您将脚本放入HTML正文中时,它会在 之前执行, jQuery已加载到正文的末尾,因此jQuery $
是未定义的。
将脚本移动到jQuery,Bootstrap和Popper之后,或移动到HTML HEAD标签。
并且,请确保工具提示具有标题。
<button type="button" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="My title">
Tooltip on top
</button>