我很难过。我在wordpress主题的footer.php中添加了一个简单的jquery函数,但它似乎没有做任何事情。我尝试了一个更简单的hide();功能,也没有触发。我根本无法获得任何jQuery,但jquery库肯定会加载到我的主题中(它基于二十几十年)。这里是我的代码:简单的jQuery功能不起作用
</footer><!-- #colophon -->
</div><!-- #page -->
<script>
jQuery(document).ready(function ($) {
$(".sub-menu").effect("highlight", {}, 3000);
});
</script>
<?php wp_footer(); ?>
</body>
</html>
我通过我的functions.php加载的jQuery UI的核心作用,并认为它显示了在该网站的资源,当我使用Chrome检查,这样的亮点();功能应该工作。
Here's the page it should be working on
为什么不jQuery的脚本运行?
谢谢!
肯尼
编辑
最终代码如下(可悲的是,我不知道如何通过<li>
元素使效果递归,但这并工作):
<script>
jQuery(document).ready(function ($) {
setTimeout(function() {
$('.sub-menu li:first-child').animate({ marginRight: '15px' }, 500);
$('.sub-menu li:first-child').animate({ marginRight: '0' }, 500);
setTimeout(function() {
$('.sub-menu li:nth-child(2)').animate({ marginRight: '15px' }, 500);
$('.sub-menu li:nth-child(2)').animate({ marginRight: '0' }, 500);
}, 400);
setTimeout(function() {
$('.sub-menu li:nth-child(3)').animate({ marginRight: '15px' }, 500);
$('.sub-menu li:nth-child(3)').animate({ marginRight: '0' }, 500);
}, 800);
setTimeout(function() {
$('.sub-menu li:nth-child(4)').animate({ marginRight: '15px' }, 500);
$('.sub-menu li:nth-child(4)').animate({ marginRight: '0' }, 500);
}, 1200);
}, 3000);
}(jQuery));
</script>
尝试运行'$(function(){console.log(typeof jQuery);});'看看它是否被加载,以检查是否真的加载,或者如果问题是无效的文档。 ready函数, – adeneo
而你并不是说没有JavaScript错误? –
行'$(“。sub-menu”)。effect(“highlight”,{},3000);'正在运行。尝试在'function($)'中取出'$',或者在下一行的大括号之后加上'(jQuery)'。 – Andrew