简体   繁体   English

在function.php中排队脚本后,Javascript无法在wordpress上运行

[英]Javascript not working on wordpress after enqueue script in functions.php

I want to add a javascript file but it is not working. 我想添加一个javascript文件,但无法正常工作。 I am using the Avada theme. 我正在使用Avada主题。 I put this at the top of my functions.php document. 我将此放在我的functions.php文件的顶部。 I saved the but I do not see it in the source code on the page. 我保存了,但在页面的源代码中看不到它。 I am trying to get the script to work on this page: http://192.185.2.154/~sogo/tempsourceoneevents.com/exhibitor-services/build-a-booth/ 我正在尝试使脚本在此页面上工作: http://192.185.2.154/~sogo/tempsourceoneevents.com/exhibitor-services/build-a-booth/ : http://192.185.2.154/~sogo/tempsourceoneevents.com/exhibitor-services/build-a-booth/

The code in functions.php functions.php中的代码

<?php

function my_scripts_method() {
    wp_enqueue_script(
        'custom-script',
        get_template_directory_uri() . '/js/bab.js',
        array( 'jquery' )
    );
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

The answer to my problem was in the comments by @adeneo, I needed to edit my javascript file 我的问题的答案是@adeneo的评论,我需要编辑我的javascript文件

"Nope, you can replace $(document).ready with jQuery(function($) { ... }); in Wordpress, that locks the value of the dollarsign in, so you can use the dollarsign inside that DOM ready function." “不,您可以用jQuery(function($){...});将$ {document).ready替换为jQuery(function($){...});在Wordpress中,它可以锁定dollarign的值,因此您可以在DOM ready函数中使用dollarign。 ”

Try this code.. 试试这个代码。

You need to add jquery library first 您需要先添加jQuery库

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript" src="http://192.185.2.154/~sogo/tempsourceoneevents.com/wp-content/uploads/bab.js"></script>

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

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