我有一个安装了Bootstrap 4主题的wordpress网站。我正在研究儿童主题。
主题附带了带有popper.js的jquery,因此所有的javascript都应该就位。
我尝试将其添加到我的计算机中:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
并在我的元素上设置属性。将不起作用。
我尝试设置此设置:
<script type="text/javascript">
$('.tooltip-test').tooltip();
</script>
<a href="#" class="tooltip-test" title="" data-original-title="Tooltip">This link</a>
将无法正常工作。它在我的网站https://www.casinoguide.dk/上-我无法确定所包含的javascript中是否缺少任何内容。
我在本地主机上工作,第二次尝试时收到以下错误: “未捕获的TypeError:$不是函数”
有人可以指出我正确的方向吗?
最好的问候 拉斯穆斯
答案 0 :(得分:0)
Try using the more verbose jQuery(...)
syntax instead:
jQuery(function () {
jQuery('[data-toggle="tooltip"]').tooltip()
})
This happens because different plugins may already use the $
character, so jQuery has a no conflict call to make sure it doesn't break other stuff inadvertently. Check out the jQuery.noConflict()
documentation for more information. This shows a nice workaround where you can still use $
, as long as it's in a function.
Seeing as you usually want your code to only run when jQuery is ready, you might as well do it in the ready()
function. So your code above could be changed to:
jQuery( document ).ready(function( $ ) {
$('[data-toggle="tooltip"]').tooltip();
});
As long as your jQuery code is inside the function above, you are fine to keep using $
.