有时候仅仅需要这一个函数的时候,又不想调用整个jq,找了一段国外大佬的代码。
(function(){var A=!!(window.attachEvent&&!window.opera);var B=/webkit\/(\d+)/i.test(navigator.userAgent)&&(RegExp.$1<525);var C=[];var D=function(){for(var E=0;E<C.length;E++)C[E]();};var F=document;F.ready=function(f){if(!A&&!B&&F.addEventListener)return F.addEventListener(‘DOMContentLoaded’,f,false);if(C.push(f)>1)return;if(A)(function(){try{F.documentElement.doScroll(‘left’);D();}catch(err){setTimeout(arguments.callee,0);}})();else if(B)var G=setInterval(function(){if(/^(loaded|complete)$/.test(F.readyState))clearInterval(G),D();},0);};})();
document.ready(function(){
//自定义操作
});