简体   繁体   English

我无法让我的jquery在我的wordpress网站上工作

[英]I can't get my jquery to work in my wordpress site

I was told that jquery was automagically included in wordpress from the get go, but I went ahead and included jquery in my functions.php. 有人告诉我,jQuery从一开始就自动包含在wordpress中,但是我继续将jquery包含在我的functions.php中。 I'm trying to do a simple script that scrolls down to a div#id when a link is clicked. 我正在尝试做一个简单的脚本,单击链接后它会向下滚动到div#id。

I created this script: 我创建了这个脚本:

jQuery(document).ready(function($) {
  jQuery("#view-visibility").click(function() {
   jQuery('html, body').animate({
    scrollTop: jQuery("#visibility").offset().top
   }, 2000);
  });
)};

I put the script in my own file, script.js, and added it to the functions.php: 我将脚本放在自己的文件script.js中,并将其添加到functions.php中:

` `

function theme_js() {
  //parameters: 1.handle, 2.path, 3.array of dependents, 4.version specification, 5.load in footer? true or false
  wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', '', '3.1.1', true );
  wp_enqueue_script( 'bootstrap_js', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js', array('jquery'), '', true );
  wp_enqueue_script( 'my_js', get_template_directory_uri() . '/script.js', array('jquery'), '', true );

}

add_action( 'wp_enqueue_scripts', 'theme_js' );`

I still can't get it to work... I don't know what the deal is!! 我仍然无法正常工作...我不知道这是什么交易! Should I be loading jquery in the head or before the body? 我应该在头部或身体之前加载jQuery吗?

Link to my site http://jakeford.io/pwi-project 链接到我的网站http://jakeford.io/pwi-project

Learn to use the developer tools in Firefox (or Firebug ) or Chrome or Safari or IE to check for Javascript and other console errors. 了解如何使用Firefox (或Firebug ), ChromeSafariIE中的开发人员工具来检查Javascript和其他控制台错误。

In the console, I see SyntaxError: Unexpected token ')' on line 9 of script.js. 在控制台中,我SyntaxError: Unexpected token ')' on line 9 of script.js.看到SyntaxError: Unexpected token ')' on line 9 of script.js.

So try }); }); 因此,尝试}); }); }); });

I have checked your site's script.js it does have syntax errors, try the code bellow: 我已经检查了您网站的script.js它确实存在语法错误,请尝试以下代码:

jQuery(document).ready(function(jQuery) {

  jQuery("#view-visibility").click(function() {
  jQuery('html, body').animate({
      scrollTop: jQuery("#visibility").offset().top
  }, 2000);
  });
    jQuery('.my-slider').unslider({
      autoplay: true
    });
});

replace jQuery with $: 用$替换jQuery:

$(document).ready(function($) {
  $("#view-visibility").click(function() {
   $('html, body').animate({
    scrollTop: $("#visibility").offset().top
   }, 2000);
  });
)};

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

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