无法在自定义WordPress主题中运行JS文件
Unable to run JS file in custom WordPress theme
我正在将 Bootstrap 模板转换为 WordPress 主题,我在 functions.php 中引用了我所有的样式表和脚本,并在页脚.php中引用了一些初始化代码,但有一个特定的文件没有正确执行:http://blackrockdigital.github.io/startbootstrap-creative/js/creative.js。
脚本:
(function($) {
"use strict"; // Start of use strict
// jQuery for page scrolling feature - requires jQuery Easing plugin
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top - 50)
}, 1250, 'easeInOutExpo');
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top',
offset: 51
})
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
$('.navbar-toggle:visible').click();
});
// Fit Text Plugin for Main Header
$("h1").fitText(
1.2, {
minFontSize: '35px',
maxFontSize: '65px'
}
);
// Offset for Main Navigation
$('#mainNav').affix({
offset: {
top: 100
}
})
// Initialize WOW.js Scrolling Animations
new WOW().init();
})(jQuery); // End of use strict
我已经将这个特定的文件设置为使用 jQuery 并通过 functions.php 在 </body>
标签之前调用,但里面的脚本都没有执行,Chrome 返回了此错误:
Uncaught TypeError: $(...).scrollspy is not a function
我尝试用 jQuery
替换$
别名,但没有效果。我还确认这是在jQuery库之后调用的。
任何帮助将不胜感激。谢谢!
我想你忘记链接bootstrap.min.js或者正确链接它
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
相关文章:
- 如何使用Gmail运行.js文件
- 当运行JS函数时,如何在c#中的Edgejs中获取错误文本
- 按钮未运行为按钮,找不到如何使运行JS文件
- 在单独的上下文中运行 js 代码并访问其全局变量
- 如何使用 GetValues 使用 Jint 运行 Js 代码
- 节点webkit仅运行.js文件
- 如何在Jasmine中运行js函数
- Ubuntu试图运行.js文件得到抛出错误;
- 在pink-in上运行js;在pink-out上运行不同的js
- 加载图像后运行JS
- 从命令行运行JS文件
- 如何在命令提示符下运行js文件
- Meteor/Iron路由器-何时何地运行JS以交换到所见即所得
- 按顺序运行Js代码
- 在终端中使用imacros运行JS
- 无法在 Windows 上的节点中运行.js文件
- 如何使用 Muse 参数进行布尔比较以运行 JS 函数
- 运行 JS 对象列表
- 防止动画多次运行 - js 回调
- 从子窗口的父窗口运行JS函数