日期:2014-05-16  浏览次数:20344 次

javascript 常用函数实现

var core= {
	$ : function(objName) {
		if (document.getElementById) {
			return eval('document.getElementById("' + objName + '")')
		} else {
			return eval('document.all.' + objName)
		}
	},
	isIE : navigator.appVersion.indexOf("MSIE") != -1 ? true : false,
	addEvent : function(l, i, I) {
		if (l.attachEvent) {
			l.attachEvent("on" + i, I)
		} else {
			l.addEventListener(i, I, false)
		}
	},
	delEvent : function(l, i, I) {
		if (l.detachEvent) {
			l.detachEvent("on" + i, I)
		} else {
			l.removeEventListener(i, I, false)
		}
	},
	readCookie : function(O) {
		var o = "", l = O + "=";
		if (document.cookie.length > 0) {
			var i = document.cookie.indexOf(l);
			if (i != -1) {
				i += l.length;
				var I = document.cookie.indexOf(";", i);
				if (I == -1)
					I = document.cookie.length;
				o = unescape(document.cookie.substring(i, I))
			}
		};
		return o
	},
	writeCookie : function(i, l, o, c) {
		var O = "", I = "";
		if (o != null) {
			O = new Date((new Date).getTime() + o * 3600000);
			O = "; expires=" + O.toGMTString()
		};
		if (c != null) {
			I = ";domain=" + c
		};
		document.cookie = i + "=" + escape(l) + O + I
	},
	readStyle : function(I, l) {
		if (I.style[l]) {
			return I.style[l]
		} else if (I.currentStyle) {
			return I.currentStyle[l]
		} else if (document.defaultView && document.defaultView.getComputedStyle) {
			var i = document.defaultView.getComputedStyle(I, null);
			return i.getPropertyValue(l)
		} else {
			return null
		}
	}
};
?