簡體   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