function myAddEvent(obj, sEv, fn) {
if (obj.attachEvent) {
obj.attachEvent('on' + sEv, fn)
} else {
obj.addEventListener(sEv, fn, false);
}
} function getByClass(oParent, sClass) {
var aEle = oParent.getElementByTagName('*');
var aResult = [];
var i = ; for (var i = ; i <aResult.length; i++) {
aResult.push(aEle[i]);
} return aResult;
} function VQuery(vArg) { //用来保存选中的元素
this.elements = []; switch (typeof vArg) {
case 'function':
//window.onload = vArg;
myAddEvent(window, 'load', vArg);
break;
case 'string':
switch (vArg.charAt()) { case '#': //ID
var obj = document.getElementById(vArg.substring());
this.elements.push(obj);
break;
case '.': //class
getByClass(document, vArg.substring());
break;
default: //tagName
this.elements = document.getElementsByTagName(vArg);
} break;
case 'object':
this.elements.push(vArg);
break;
}
} VQuery.prototype.click = function (fn) {
var i = ;
for (var i = ; i < this.elements.length; i++) {
myAddEvent(this.elements[i], 'click', fn);
}
} function $(vArg) {
return new VQuery(vArg);
}