模拟jquery选择器
2013-05-31 12:52 lyw90 阅读(163) 评论(0) 编辑 收藏 举报function VQuery(vArg)
{
//用来保存选中的元素
this.elements=[];
switch(typeof vArg)
{
case 'function':
//window.onload=vArg;
myAddEvent(window, 'load', vArg);
break;
case 'string':
switch(vArg.charAt(0))
{
case '#': //ID
var obj=document.getElementById(vArg.substring(1));
this.elements.push(obj);
break;
case '.': //class
this.elements=getByClass(document, vArg.substring(1));
break;
default: //tagName
this.elements=document.getElementsByTagName(vArg);
}
break;
case 'object':
this.elements.push(vArg);
}
}