Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery脚本在Wordpress中不起作用,尝试了多种排队方法_Javascript_Jquery_Wordpress - Fatal编程技术网

Javascript Jquery脚本在Wordpress中不起作用,尝试了多种排队方法

Javascript Jquery脚本在Wordpress中不起作用,尝试了多种排队方法,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我搜索过类似的问题,但还没有找到答案 在使用Genesis框架的Wordpress上,我尝试使用以下jquery脚本:Matt Verone的Dynamic to top(WP插件版本和手动)。两者都不起作用。我在可湿性粉剂和非可湿性粉剂网站上成功地使用了这两种方法 我通过functions.php中的以下方法将smoothscroll.js和dynamic to top脚本(手动使用时)放入队列,easing.js和jquery.ui.totop.min.js function tm_scri

我搜索过类似的问题,但还没有找到答案

在使用Genesis框架的Wordpress上,我尝试使用以下jquery脚本:Matt Verone的Dynamic to top(WP插件版本和手动)。两者都不起作用。我在可湿性粉剂和非可湿性粉剂网站上成功地使用了这两种方法

我通过functions.php中的以下方法将smoothscroll.js和dynamic to top脚本(手动使用时)放入队列,easing.js和jquery.ui.totop.min.js

function tm_scripts()
{       
    wp_register_script( 'easing', get_stylesheet_directory_uri() . '/lib/js/easing.js', array( 'jquery' ), null, true );

    wp_register_script( 'smoothscroll', get_stylesheet_directory_uri() . '/lib/js/smoothscroll.js', array( 'jquery' ), null, true );

    wp_register_script( 'jquery.ui.totop.min', get_stylesheet_directory_uri() . '/lib/js/jquery.ui.totop.min.js', array( 'jquery' ), null, true );

    wp_register_script( 'main', get_stylesheet_directory_uri() . '/lib/js/main.js', array( 'jquery' ), null, true );

    wp_enqueue_script( 'easing' );
    wp_enqueue_script( 'smoothscroll' );
    wp_enqueue_script( 'jquery.ui.totop.min' );
    wp_enqueue_script( 'main' );
}
add_action( 'wp_enqueue_scripts', 'tm_scripts' );
当我查看代码时,它们出现在页脚中

然后,我尝试了让jquery通过wp加载,以及CSS技巧中的以下jquery排队方法:

 if (!is_admin()) add_action("wp_enqueue_scripts", "tm_jquery_enqueue", 11);
function tm_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');  
}

不走运。我使用的其他插件只有ContactForm7和Akismet。我觉得有些地方有冲突,只是不确定是什么。任何帮助都将不胜感激。

CSS技巧代码对我也不起作用,但这是

add_action( 'init', 'jquery_register' );
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ('http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' ), false, null, true );
wp_enqueue_script( 'jquery' );
}
}

或者任何其他jquery版本…

使用样板文件是解决JS冲突和清理请求的好方法,您应该试试。不过,很好的网站。你有任何控制台错误吗?谢谢@jeromeM。是的,我在我的非wp网站上使用样板文件。当我使用DynamictoTop插件时,我没有收到任何错误。但是,当我将所有脚本(smoothscroll.js、easing.js、…totop.min.js和main.js)排队时,我在main.js上得到了一个错误,它包含
$(document).ready(function(){$().uitop({easingType:'easeOutQuart'});})
错误显示“$不是函数。”
$
只是
jQuery
的别名,通过调用
$.noConflict()
,在将其余脚本排队之前,可以将
$
的控制权返回jQuery。看见