我需要在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 :(得分: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);
});