js 로 컬 추가 방법

5528 단어 js
/**
 * @author wsf
 */
/**
 *        val  
 */
if (!Object.prototype.val) {
	Object.prototype.val = function() {
		return this.valueOf();
	}
}
/**
 *           
 */
if (!Object.prototype.isNumber) {
	String.prototype.isNumber = function() {
		return !this || isNuN(this.val()) ? false : ( typeof this.val() === "number");
	}
}
/**
 *      remove  
 */
if (!Array.prototype.remove) {
	Array.prototype.remove = function(s) {
		for (var i = this.length; i >= 0; i--) {
			if (s === this[i])
				this.splice(i, 1);
		}
	}
}
/**
 *          apply       json  
 */
if (!Object.prototype.applyAll) {
	Object.prototype.applyAll = function(callback) {
		if (!this)
			return;
		var idx = 0;
		if (this.remove && this[0]) {
			//  
			for (var o = this[0]; idx < this.length && callback.call(o, idx, o) != false; o = this[++idx]) {
			}
		} else {
			//  
			for (var i in this) {
				if (callback.call(this[i], i, this[i]) === false)
					break;
			}
		}
	}
}
/**
 *      indexOf  
 */
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(o) {
		for (var i = this.length; i >= 0; i--) {
			if (this[i] === o)
				return i;
		}
		return -1;
	}
}
/**
 *      contain  
 */
if (!Array.prototype.contain) {
	Array.prototype.contain = function(o) {
		var validx = this.indexOf(o)//    
		return validx > 0;
	}
}
/**
 *      put  (          )
 */
if (!Array.prototype.put) {
	Array.prototype.put = function(o, idx) {
		return this.splice(idx, 0, o);
	}
}
/**
 *        intVal  
 */
if (!String.prototype.intVal) {
	String.prototype.intVal = function() {
		return parseInt(this);
	}
}
/**
 *        doubleVal  
 */
if(!String.prototype.doubleVal){
	String.prototype.doubleVal = function (){
		return parseDouble(this);
	}
}
/**
 * id        
 */

function selc(s) {
	if (s.indexOf("#") > 0)
		return document.getElementById(s.replace("#", ""));
	else if (s.indexOf(".") > 0) {
		var result = [];
		var a = selector.split(".");
		var prefix = a[0] || "*";
		//  
		var suffix = a[1];
		//  
		var docs = document.getElementsByTagName(prefix);
		docs.applyAll(function() {
			if (this.nodeType === 1 && this.id) {
				var classNames = this.className.split(/\s+/g);
				//    
				var finded = this;
				classNames.applyAll(function() {
					if (this === suffix)
						result.push(finded);
				});
			}
		});
		return result;
		//      
	}
}

/**
 * ajax  
 * @param {} options
 */
function ajax(options) {
	var httpRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	httpRequest.onreadystatechange = function() {
		var dataType = options.dataType.toLowerCase();
		httpRequest.readyState === 4 && httpRequest.status === 200 && options.callback(dataType === "json" ? eval("(" + httpRequest.responseText + ")") : dataType === "xml" ? httpRequest.responseXML : httpRequest.responseText, options.context);
	};
	httpRequest.open(options.mode, options.url, options.sync);
	if (options.mode.toLowerCase() === "post") {
		httpRequest.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded;charset=utf-8");
	}
	options.mode.toLowerCase() === "get" ? httpRequest.send(null) : httpRequest.send(options.params);
}

/**
 * Map  
 */
var Map = function() {
	this.flag = false;
	this.store = new Array();
	if (!this.flag) {
		Map.prototype.entry = function(key, val) {
			this.key = key;
			this.val = val;
		}
		Map.prototype.put = function(key, val) {
			this.store[this.store.length] = new this.entry(key, val);
		}
		Map.prototype.get = function(key) {
			for (var i = this.store.length - 1; i >= 0; i--) {
				if (this.store[i].key === key)
					return this.store[i].val;
			}
			return null;
		}
		Map.prototype.remove = function(key) {
			for (var i = this.store.length - 1; i >= 0; i--) {
				this.store[i].key === key && this.store.splice(i, 1);
			}
		}
		Map.prototype.keySet = function() {
			var keys = new Array();
			for (var i = 0; i <= this.store.length - 1; i++) {
				keys.push(this.store[i].key);
			}
			return keys;
		}
		Map.prototype.valSet = function() {
			var vals = new Array();
			for (var i = 0; i <= this.store.length - 1; i++) {
				vals.push(this.store[i].val);
			}
			return vals;
		}
		Map.prototype.clear = function() {
			this.store.length = 0;
		}
		Map.prototype.size = function() {
			return this.store.length;
		}
		this.flag = true;
	}
}

좋은 웹페이지 즐겨찾기