[英]jQuery Javascript not working on Wordpress
I've been trying to add my custom jQuery script to wordpress, the script code and all is working on jsfiddle when I choose the jquery library, but when I'm trying to add it on wordpress it is not working. 我一直试图将我的自定义jQuery脚本添加到wordpress中,脚本代码,当我选择jquery库时,所有代码都在jsfiddle上运行,但是当我尝试在wordpress上添加它时,它不起作用。 Here's how added the wp enqueue code:
以下是添加wp排队代码的方法:
function cb_scroller() {
//wp_enqueue_script('jquery');
wp_register_script( 'scroller', get_template_directory_uri() . '/js/scroller.js', array('jquery'),'',true );
wp_enqueue_script( 'scroller' );
}
add_action( 'wp_enqueue_scripts', 'cb_scroller' );
So what may be the problem? 那么可能是什么问题呢? here's the jsfiddle attempt: https://jsfiddle.net/naimelhajj/q4bdfcwb/ (disregard the styling, I've imported the css and js as "external resources")
这是jsfiddle的尝试: https ://jsfiddle.net/naimelhajj/q4bdfcwb/(不考虑样式,我已经将CSS和js导入为“外部资源”)
This is your script (which you should have posted in the question) 这是您的脚本(您应该在问题中发布该脚本)
$(document).ready(function(){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
Wordpress is in no-conflict mode by default, which means $
is not defined, it has to be 默认情况下,Wordpress处于无冲突模式,这意味着未定义
$
,它必须是
jQuery(document).ready(function($){
$(".arrow-left").click(function(){
$(".site-main-gluten").animate({scrollLeft: "-="+100});
});
$(".arrow-right").click(function(){
$(".site-main-gluten").animate({scrollLeft: "+="+100});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.