0
以下功能没有在FF和IE工作时,我把它称为对windows.load事件window.load工作在Chrome,但不是在FF和IE
$(window).load(function() { $("html").replaceText(/\[.*\]/,""); }
但在铬工作正常,如果我叫它的document.ready事件和它的作品反之亦然
功能
$.fn.replaceText = function(search, replace, text_only) {
return this.each(function(){
var v1, v2, rem = [];
$(this).find("*").andSelf().contents().each(function(){
if(this.nodeType === 3) {
v1 = this.nodeValue;
v2 = v1.replace(search, replace);
if(v1!=v2) {
if(!text_only && /<.*>/.test(v2)) {
$(this).before(v2);
rem.push(this);
}
else this.nodeValue = v2;
}
}
});
if(rem.length) $(rem).remove();
});
};
该功能确实_expensive_,浏览器很差。 – undefined
你有什么错误吗?如果你把'console.log($(“html”));'放在函数中,你看到了什么? – Barmar
它不会在控制台中输出任何错误 – AZee