2015-02-09 61 views
1

我需要在Adobe Business Catalyst中的不可訪問模塊中更改文本,因爲我有以下工作,但屏幕上的選項一旦更新,腳本就不會再運行。我如何使它自動刷新/運行?動態選擇後腳本更改名稱停止動態選擇

$(document).ready(function(){ 
$.fn.replaceText = function(search, replace, text_only) { 
    return this.each(function(){ 
    var node = this.firstChild, 
     val, 
     new_val, 
     remove = []; 
    if (node) { 
     do { 
     if (node.nodeType === 3) { 
      val = node.nodeValue; 
      new_val = val.replace(search, replace); 
      if (new_val !== val) { 
      if (!text_only && /</.test(new_val)) { 
       $(node).before(new_val); 
       remove.push(node); 
      } else { 
       node.nodeValue = new_val; 
      } 
      } 
     } 
     } while (node = node.nextSibling); 
    } 
    remove.length && $(remove).remove(); 
    }); 
}; 
$("#shippingStateSpan").replaceText("Destination State", "Do you have a VAT number?"); 
}); 

任何幫助將不勝感激。謝謝

回答

0

我猜測,當頁面上的選擇被改變時,文本被替換。試試這個:

$(document).ready(function() { 
$.fn.replaceText = function(search, replace, text_only) { 
    return this.each(function() { 
     var node = this.firstChild, 
      val, 
      new_val, 
      remove = []; 
     if (node) { 
      do { 
       if (node.nodeType === 3) { 
        val = node.nodeValue; 
        new_val = val.replace(search, replace); 
        if (new_val !== val) { 
         if (!text_only && /</.test(new_val)) { 
          $(node).before(new_val); 
          remove.push(node); 
         } else { 
          node.nodeValue = new_val; 
         } 
        } 
       } 
      } while (node = node.nextSibling); 
     } 
     remove.length && $(remove).remove(); 
    }); 
}; 
var refreshIds = setInterval('$("#shippingStateSpan").replaceText("Destination State", "Do you have a VAT number?")', 300); 
}); 
+0

不得不改變它的目的地國家反對航運選項,但它現在工作!感謝您的幫助! – Jammie 2015-02-12 16:05:04

+0

對不起 - 爲了在爲您提供解決方案之前測試我自己,我會更新以符合您的問題。 – Neido 2015-02-13 11:02:40