简体   繁体   English

如何使此脚本在Wordpress上运行?

[英]How can I make this script to run on Wordpress?

I have this script: 我有这个脚本:

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

Code html: 代码html:

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

I want to apply this script to my website in Wordpress. 我想将此脚本应用于Wordpress中的网站。

I put this code in functions.php 我把这段代码放在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 );

}

It is a very simple script that works smoothly on local Wordpress but we did not implement it. 这是一个非常简单的脚本,可以在本地Wordpress上顺利运行,但是我们没有实现它。

Is something wrong? 有什么事吗

Can you help me to solve this problem? 您能帮我解决这个问题吗?

Thanks in advance! 提前致谢!

You forgot to add a . 您忘记添加。 before the selector for class text1 --> "text1" 在类text1的选择器之前->“ text1”

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

WordPress uses noconflict so you have to wrap your scripts in jQuery(function($) {}); WordPress使用noconflict,因此您必须将脚本包装在jQuery(function($) {}); in order to be able to use the dollar sign. 为了能够使用美元符号。 Like so: 像这样:

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

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

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