简体   繁体   English

无法让 jquery 功能在 wordpress 网站上工作

[英]Can't get jquery function to work on wordpress site

My jquery function works fine on local, but once I add it to my WP footer and upload, nothing.我的 jquery 函数在本地运行良好,但是一旦我将它添加到我的 WP 页脚并上传,什么都没有。

There are a lot of scripts on this page, the but the script I'm trying to make work is this:这个页面上有很多脚本,但我试图制作的脚本是这样的:

    jQuery(document).ready(function($){
  $("li.accordion").on('click',function() {
    $('.mega-sub-menu', this).slideToggle("fast", function() {});
  });
});

Jquery is loaded and working, but this script won't function. Jquery 已加载并正常工作,但此脚本将无法运行。

Any ideas?有任何想法吗?

EDIT: Thanks, but it wasn't the stray '编辑:谢谢,但这不是流浪者

I seemed to be having a cache issue on the site, which has been updated now.我似乎在网站上遇到了缓存问题,现在已经更新。 Still having the problem.还是有问题。

EDIT2: Removed a link EDIT2:删除了一个链接

Your site has a syntax error on it.您的网站有语法错误。 There is a quote at the end of your JavaScript which may well be causing it to not execute. JavaScript 末尾有一个引号,很可能导致它无法执行。

jQuery(document).ready(function(){
    jquery("li.accordion").click(function() {
        jquery('.mega-sub-menu', this).slideToggle("fast", function() {});
    });
});' <--- quote here

Ok, you've fixed that now, and all the JavaScript is working, but I can see the next issue that prevents the menu from showing is a CSS rule with !important.好的,你现在已经解决了这个问题,所有的 JavaScript 都在工作,但我可以看到阻止菜单显示的下一个问题是一个带有 !important 的 CSS 规则。 (It's overriding the style="display:block" attribute on the mega-sub-menu that is added via JQuery). (它覆盖了通过 JQuery 添加的超级子菜单上的 style="display:block" 属性)。

超级子菜单

So after doing a little more googling, I came up with this answer:所以在做了更多的谷歌搜索之后,我想出了这个答案:

jQuery(function($){
    $('li.accordion').click(function() {
             $('.mega-sub-menu', this).slideToggle('fast', function() {});
    }).click();

});

Here we simulate the click so that the accordion starts out closed and I don't need to add any more CSS to anything.在这里,我们模拟点击,以便手风琴开始关闭,我不需要向任何内容添加更多 CSS。

I added important to the CSS earlier to overcome the inline style — like an idiot, not realizing that the jquery was adding the inline style (I think that's what I did anyway, it was inappropriately late.)我之前在 CSS 中添加了 important 来克服内联样式——就像一个白痴,没有意识到 jquery 正在添加内联样式(我认为无论如何我就是这样做的,晚了不合适。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM