标签:
//向系统内置的window.onLoad函数,添加处理事件
function addLoadEvent(func){ var oldOnLoad=window.onload; if(typeof window.onload!="function"){ window.onload=func; }else{ window.onload=function(){ oldOnLoad(); func(); } } }
//向目标元素targetElement后增添一个新元素newElement
function insertAfter(newElement,targetElement){ var parent=targetElement.parentNode; if(parent.lastChild==targetElement){ parent.appendChild(newElement); }else{ parent.insertBefore(newElement,targetElement.nextSibling); } }
//获取ajax中的XMLHttpRequest对象,保证各个浏览器的兼容
//获取ajax中的XMLHttpRequest对象,保证各个浏览器的兼容 function getHttpObject(){ if(typeof XMLHttpRequest=="undefined"){ XMLHttpRequest=function(){ try{ return new ActiveXObject("Msxml2.XMLHttp.6.0"); }catch(e){} try{ return new ActiveXObject("Msxml2.XMLHttp.3.0"); }catch(e){} try{ return new ActiveXObject("Msxml2.XMLHttp"); }catch(e){} return false; } } return new XMLHttpRequest(); }
前端学习之二_JS公共库(addLoadEvent,insertAfter,getHttpObject)
标签:
原文地址:http://www.cnblogs.com/bobodeboke/p/4462238.html