简体   繁体   English

即使尝试noConflict也无法使jQuery代码在Wordpress中工作

[英]Can't get jQuery code to work in Wordpress, even trying noConflict

I have some html and css code in wordpress to make an image grid gallery, with pop up and slider. 我在wordpress中有一些html和css代码来制作图像网格库,并带有弹出窗口和滑块。 I've coded it myself due to not being able to find a plugin with wordpress to match the design I want. 我自己编写了代码,因为无法找到带有wordpress的插件来匹配我想要的设计。

I know this is working as I have a working copy on my computer locally in brackets.io. 我知道这是可行的,因为我在本地计算机上的brackets.io中有一个工作副本。 After trying and failing inserting the code in WordPRess I looked online to try and see if I could find a solution. 尝试在WordPRess中插入代码失败后,我上网查看并尝试找到解决方案。 I did wfind the jquery no conflict stuff but I am not sure if I am writing the jquery code right? 我确实找到了jquery没有冲突的东西,但是我不确定我是否正在编写jquery代码?

Here is the site in question with all the code in place (HTML and CSS to hide the content) - http://loknar.idwithin.xyz - below the jquery code I am writing. 这是一个有问题的站点,所有代码(HTML和CSS用来隐藏内容)到位-http ://loknar.idwithin.xyz-在我正在编写的jquery代码下面。 Its working on my desktop so I reckon I am writing the code wrong for the no conflict? 它可以在我的桌面上正常工作,所以我认为我将代码写错了,因为没有冲突?

Thanks. 谢谢。

$j=jQuery.noConflict();


$j(document).ready(function(){
    $(".content").slice(0, 4).show();
  $("#loadMore").on("click", function(e){
    e.preventDefault();
    $(".content:hidden").slice(0, 4).slideDown();
    if($(".content:hidden").length == 0) {
      $("#loadMore").text("No Content").addClass("noContent");
    }
  });

You need to replace every instance of $ with $j . 您需要将$j每个实例替换$ $j Otherwise you'll still get conflicts. 否则,您仍然会遇到冲突。

Use jQuery instrad of $ , it happended to me in the past and it worked that way. 使用$ jQuery instrad,它在我以前发生过并且以这种方式工作。 The no-conflict mode is not necessary. 无需冲突模式。

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

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