如何使此脚本在Wordpress上运行? [英] How can I make this script to run on Wordpress?

查看:88
本文介绍了如何使此脚本在Wordpress上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本:

$(document).ready(function(){
    $("text1").click(function(){
        $(this).hide();
    });
});

代码html:

 <div class="div1">
    <p class="text1">text to appear when the user puts the mouse over</p>
</div>

我想将此脚本应用于Wordpress中的网站.

I want to apply this script to my website in Wordpress.

我将这段代码放在functions.php中

I put this code in functions.php

  add_action( 'wp_enqueue_scripts', 'script_echipa' );
function script_echipa() 

{ wp_enqueue_script( 'script', get_template_directory_uri() . '/js/echipa.js', array('jquery'), null, true );

}

这是一个非常简单的脚本,可以在本地Wordpress上顺利运行,但我们并未实现.

It is a very simple script that works smoothly on local Wordpress but we did not implement it.

有什么问题吗?

您能帮我解决这个问题吗?

Can you help me to solve this problem?

提前谢谢!

推荐答案

WordPress使用noconflict,因此您必须将脚本包装在jQuery(function($) {});中才能使用美元符号.像这样:

WordPress uses noconflict so you have to wrap your scripts in jQuery(function($) {}); in order to be able to use the dollar sign. Like so:

jQuery(function($) {
    $(".text1").click(function() {
        $(this).hide();
    });
});

这篇关于如何使此脚本在Wordpress上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆