2015-02-09 57 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