2013-08-30 59 views
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(); 
}); 
}; 
+1

该功能确实_expensive_,浏览器很差。 – undefined

+0

你有什么错误吗?如果你把'console.log($(“html”));'放在函数中,你看到了什么? – Barmar

+0

它不会在控制台中输出任何错误 – AZee

回答

0

使用$(window).ready而非$(window).load

load对像正在完成的图像这样的东西更有用。我不会将它用于documentwindow

如果这不是答案,让我知道你为什么试图load

相关问题