繁体   English   中英

Ajax内容更改时如何调用函数?

[英]How to call function when ajax content changes?

因此,我在shopify网站上工作,并停留在编写脚本的情况下,情况是安装了一个插件以在网站上插入评论,而任务是使每个用户在紧随其后都具有“ verified Buyer”标签用户名,即使它不是经过验证的用户,因为真正的经过验证的用户通过插件具有标签,所以工作是在每个用户期望已经拥有它的用户之后插入它,我能够使用此脚本来执行此操作-

$(document).ajaxStart(function(){

function addVerified(){

    var list=document.querySelectorAll('display-wrapper .nav-content .reviews-active .review');
    for(let li of list){

        if(!li.classList.contains('hidden')&& (!li.firstElementChild.classList.contains('verified-buyer'))){
            let needElem=li.firstElementChild.children[1].firstElementChild;
            needElem.insertAdjacentHTML('afterend','<div class="label-with-tooltip pull-left">  <span class="y-label>Verified Buyer</span>   </div>'); 

        }
    }
}

addVerified();

});

当使用评论下面的分页,内容更改和评论更改且该功能无法正常工作时,一切工作均正常,因此使已验证的买方标签被删除,我尝试使用DOMSubtreeModified(使脚本陷入无限循环),ajaxComplete执行函数,但到目前为止没有任何效果,我对仍在学习的javascript知识不多,在感到沮丧之后,我决定将其发布在这里。 请帮忙

好吧...在您标记的其余部分中,我可以提出一些建议。

这是对客户的谎言……我不喜欢那样。

但是无论如何,这是对其进行调整的方法:

// Create the element to insert
var fake_verified_buyer = $('<div class="label-with-tooltip pull-left">  <span class="y-label yotpo-user-title yotpo-action-hover" data-type="toggleFade" data-target="yotpo-tool-tip">Verified Buyer</span>  <div class="yotpo-tool-tip yotpo-animation-fade" data-user-type="yotpo-verified-buyer"> <div class="tool-tip-header"> <span>What is a</span> <span class="header-green">Verified Buyer</span> </div> <div class="tool-tip-content"> A Verified Buyer is a user who has purchased the reviewed product through our store. </div> </div> </div>');

// On pagination click, insert that element after each user name, if not already present.
$(document).on("click",".yotpo-pager",function(){
  setTimeout(function(){
    $(document).find(".yotpo-user-name").each(function(){
      if(!$(this).next().is(".label-with-tooltip")){

        var clone = fake_verified_buyer.clone();
        clone.insertAfter(this);
      }
    });
  },100);
});

暂无
暂无

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

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