var queryEle = function(selector){
var selectReg = /^(#)?(\.)?(\w+)$/img;
var result = selectReg.exec(selector),
data = [];
//id
if(result[1]){
if(result[3]){
if(typeof document.querySelector=='function'){
return document.querySelector(result[1]+result[3]);
}else{
return document.getElementById(result[3]);
}
}
}else
//class
if(result[2]){
if(result[3]){
if(typeof document.getElementsByClassName=='function'){
var dom = document.getElementsByClassName(result[3]);
if(dom){
return converArr(dom);
}
}else{
var dom2 = document.getElementsByTagName('*');
for(var i=0;i<dom2.length;i++){
if(dom2[i].className.test(new RegExp(result[2]))){
data.push(dom2[i]);
}
}
}
return data;
}
}else
if(result[3]) {
var doms = document.getElementsByTagName(result[3].toLowerCase());
if(doms) {
result = converArr(doms);
}
}
return result;
};
function converArr(dom){
var arr = null;
try{
arr = Array.prototype.slice.call(dom,0);
}catch(e){
for(var i=0;i<dom.length;i++){
arr.push(dom[i]);
}
}
return arr;
}
console.log(queryEle('.left'));