1

到目前为止,我需要更改 Adob​​e 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?" );
});

任何帮助将不胜感激。谢谢

4

1 回答 1

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);
});
于 2015-02-12T06:41:17.317 回答