Javascript 如何在Wordpress环境中只在jQuery中预结束一次

Javascript 如何在Wordpress环境中只在jQuery中预结束一次,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我在Wordpress环境中工作。我使用jquery插入了一个自定义部分来显示一个“宝藏”图标,以便人们可以点击它。此图标位于通过聊天插件创建的默认“红色聊天图标”之前 这使得我创建的DIV与“红色聊天图标”直接相关。但是,每当我打开和关闭默认聊天图标时,宝藏图标每次都会重复。我该如何使“宝藏”图标在每次打开和关闭时都不会重复 jQuery jQuery(document).on("wplc_animation_done", function(e) {

我在Wordpress环境中工作。我使用jquery插入了一个自定义部分来显示一个“宝藏”图标,以便人们可以点击它。此图标位于通过聊天插件创建的默认“红色聊天图标”之前

这使得我创建的DIV与“红色聊天图标”直接相关。但是,每当我打开和关闭默认聊天图标时,宝藏图标每次都会重复。我该如何使“宝藏”图标在每次打开和关闭时都不会重复

jQuery

    jQuery(document).on("wplc_animation_done", function(e) {

                    jQuery( "#wp-live-chat-header" ).append( "<div class='wp-live-chat-extend'><h2>Chat with Us!</h2></div>" ); 

            jQuery( "#wp-live-chat" ).prepend( "<a href='/exatactical/treasure-trove/'><div id='pbf-treasure-trove' class='pbf-treasure-trove-bg'></div></a>" ); // This is what inserts the icon
            jQuery( "#pbf-treasure-trove" ).append( "<div class='wp-live-chat-extend'><h2>Treasure Trove</h2></div>" );
});
one()
只执行一次处理程序,而
on()
是持久的


您应该能够利用jQuery的
.one()
方法

jQuery(document).on("wplc_animation_done", function(e) {
    jQuery( "#wp-live-chat-header" ).append( "<div class='wp-live-chat-extend'><h2>Chat with Us!</h2></div>" ); 
    jQuery( "#pbf-treasure-trove" ).append( "<div class='wp-live-chat-extend'><h2>Treasure Trove</h2></div>" );
}).one("wplc_animation_done", function(e) {
    jQuery( "#wp-live-chat" ).prepend( "<a href='/exatactical/treasure-trove/'><div id='pbf-treasure-trove' class='pbf-treasure-trove-bg'></div></a>" ); // This is what inserts the icon
});
jQuery(document).on(“wplc\u animation\u done”,函数(e){
jQuery(“wp-live-chat头”).append(“与我们聊天!”);
jQuery(“pbf宝藏”).append(“宝藏”);
}).1(“wplc_动画_done”),函数(e){
jQuery(#wp live chat”).prepend(“”;//这是插入图标的内容
});
如有必要,还可以将其他两行放入
.one()
处理程序中

jQuery(document).one()
jQuery(document).on("wplc_animation_done", function(e) {
    jQuery( "#wp-live-chat-header" ).append( "<div class='wp-live-chat-extend'><h2>Chat with Us!</h2></div>" ); 
    jQuery( "#pbf-treasure-trove" ).append( "<div class='wp-live-chat-extend'><h2>Treasure Trove</h2></div>" );
}).one("wplc_animation_done", function(e) {
    jQuery( "#wp-live-chat" ).prepend( "<a href='/exatactical/treasure-trove/'><div id='pbf-treasure-trove' class='pbf-treasure-trove-bg'></div></a>" ); // This is what inserts the icon
});