94 添加hover方法 和show hide 方法
2015-04-29 23:55
337 查看
var $=function(_this)//调用,把this传递过来
{
return new Base(_this);
};
//对象式
function Base(_this)
{
//创建一个数组来获取节点和节点的数组
this.elements=[];//私有化,不共用
if(_this!=undefined)//这里的_this是一个对象,undefined也是个对象,却别typeof放回的带单引号的 “undefined”
{
this.elements[0]=_this; //把this放到数组的第一个
}
}
//获取ID节点
Base.prototype.getId=function(id)
{
this.elements.push(document.getElementById(id));
return this;
};
//获取元素节点
Base.prototype.getTagName=function(tag)
{
var tags=document.getElementsByTagName(tag);
for(var i=0;i<tags.length;i++)
{
this.elements.push(tags[i]);
}
return this;
};
//class获取
Base.prototype.getClass=function(className)
{
var all=document.getElementsByTagName("*");
for(var i=0;i<all.length;i++)
{
if(all[i].className==className)
{
this.elements.push(all[i]);
}
}
return this;
};
//获取某个节点
Base.prototype.eq=function(num)
{
var element=this.elements[num];
this.elements=[];//清空数组
this.elements[0]=element;//重新赋值
return this;
};
//设置css
Base.prototype.css=function(attr,value)
{
for(var i=0;i<this.elements.length;i++)
{
if(arguments.length==1)
{
if(typeof window.getComputedStyle!="undefined")
{
return window.getComputedStyle(this.elements[i],null)[attr];
}
else if(typeof this.elements[i].currentStyle !="undefined")
{
return this.elements[i].currentStyle[attr];
}
}
this.elements[i].style[attr]=value;
}
return this;
};
Base.prototype.click=function(fn)
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].onclick=fn;
}
return this;
};
//设置innerHtml 获取innerHTML
Base.prototype.html=function(value)
{
for(var i=0;i<this.elements.length;i++)
{
if(arguments.length==0)
{
return this.elements[i].innerHTML;
}
else
{
this.elements[i].innerHTML=value;
}
}
return this;
};
//添加class
Base.prototype.addClass=function(className)
{
for(var i=0;i<this.elements.length;i++)
{
if(!this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)')))//判断是否已经有这个class
{
this.elements[i].className+=' '+className;
}
}
return this;
};
//移出class
Base.prototype.removeClass=function(className) //调用方法$().getClass("dd").addClass("a").addClass("b").removeClass("b");
{
for(var i=0;i<this.elements.length;i++)
{
if(this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)')))//判断是否已经有这个class
{
this.elements[i].className=this.elements[i].className.replace(new RegExp('(\\s|^)'+className+'(\\s|$)'),'');
}
}
return this;
};
//添加link或style的css规则,不常用
Base.prototype.addRule=function(num,selectorText,cssText,position) //调用方法, $().addRule(0,"body","background:red",0)
{
var sheet=document.styleSheets[num];
if(typeof sheet.insertRule!="undefined")//w3c
{
sheet.insertRule(selectorText+"{"+cssText+"}",position);
}
else if(typeof sheet.addRule!="undefined")//iE
{
sheet.addRule(selectorText,cssText,position);//sheet.addRule("body","background:red",)
}
};
//移除link或style的css规则,不常用
Base.prototype.addRule=function(num,index) //调用方法, $().removeRule(0);
{
var sheet=document.styleSheets[num];
if(typeof sheet.deleteRule!="undefined")//w3c
{
sheet.deleteRule(index);
}
else if(typeof sheet.removeRule!="undefined")//iE
{
sheet.removeRule(index);//sheet.addRule("body","background:red",)
}
};
//设置hover方法
Base.prototype.hover=function(over,out)
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].onmouseover=over;
this.elements[i].onmouseout=out;
}
return this;
};
//添加show
Base.prototype.show=function()
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].style.display="block"
}
return this;
};
//添加hide
Base.prototype.hide=function()
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].style.display="none"
}
return this;
};
{
return new Base(_this);
};
//对象式
function Base(_this)
{
//创建一个数组来获取节点和节点的数组
this.elements=[];//私有化,不共用
if(_this!=undefined)//这里的_this是一个对象,undefined也是个对象,却别typeof放回的带单引号的 “undefined”
{
this.elements[0]=_this; //把this放到数组的第一个
}
}
//获取ID节点
Base.prototype.getId=function(id)
{
this.elements.push(document.getElementById(id));
return this;
};
//获取元素节点
Base.prototype.getTagName=function(tag)
{
var tags=document.getElementsByTagName(tag);
for(var i=0;i<tags.length;i++)
{
this.elements.push(tags[i]);
}
return this;
};
//class获取
Base.prototype.getClass=function(className)
{
var all=document.getElementsByTagName("*");
for(var i=0;i<all.length;i++)
{
if(all[i].className==className)
{
this.elements.push(all[i]);
}
}
return this;
};
//获取某个节点
Base.prototype.eq=function(num)
{
var element=this.elements[num];
this.elements=[];//清空数组
this.elements[0]=element;//重新赋值
return this;
};
//设置css
Base.prototype.css=function(attr,value)
{
for(var i=0;i<this.elements.length;i++)
{
if(arguments.length==1)
{
if(typeof window.getComputedStyle!="undefined")
{
return window.getComputedStyle(this.elements[i],null)[attr];
}
else if(typeof this.elements[i].currentStyle !="undefined")
{
return this.elements[i].currentStyle[attr];
}
}
this.elements[i].style[attr]=value;
}
return this;
};
Base.prototype.click=function(fn)
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].onclick=fn;
}
return this;
};
//设置innerHtml 获取innerHTML
Base.prototype.html=function(value)
{
for(var i=0;i<this.elements.length;i++)
{
if(arguments.length==0)
{
return this.elements[i].innerHTML;
}
else
{
this.elements[i].innerHTML=value;
}
}
return this;
};
//添加class
Base.prototype.addClass=function(className)
{
for(var i=0;i<this.elements.length;i++)
{
if(!this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)')))//判断是否已经有这个class
{
this.elements[i].className+=' '+className;
}
}
return this;
};
//移出class
Base.prototype.removeClass=function(className) //调用方法$().getClass("dd").addClass("a").addClass("b").removeClass("b");
{
for(var i=0;i<this.elements.length;i++)
{
if(this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)')))//判断是否已经有这个class
{
this.elements[i].className=this.elements[i].className.replace(new RegExp('(\\s|^)'+className+'(\\s|$)'),'');
}
}
return this;
};
//添加link或style的css规则,不常用
Base.prototype.addRule=function(num,selectorText,cssText,position) //调用方法, $().addRule(0,"body","background:red",0)
{
var sheet=document.styleSheets[num];
if(typeof sheet.insertRule!="undefined")//w3c
{
sheet.insertRule(selectorText+"{"+cssText+"}",position);
}
else if(typeof sheet.addRule!="undefined")//iE
{
sheet.addRule(selectorText,cssText,position);//sheet.addRule("body","background:red",)
}
};
//移除link或style的css规则,不常用
Base.prototype.addRule=function(num,index) //调用方法, $().removeRule(0);
{
var sheet=document.styleSheets[num];
if(typeof sheet.deleteRule!="undefined")//w3c
{
sheet.deleteRule(index);
}
else if(typeof sheet.removeRule!="undefined")//iE
{
sheet.removeRule(index);//sheet.addRule("body","background:red",)
}
};
//设置hover方法
Base.prototype.hover=function(over,out)
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].onmouseover=over;
this.elements[i].onmouseout=out;
}
return this;
};
//添加show
Base.prototype.show=function()
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].style.display="block"
}
return this;
};
//添加hide
Base.prototype.hide=function()
{
for(var i=0;i<this.elements.length;i++)
{
this.elements[i].style.display="none"
}
return this;
};
相关文章推荐
- fragment添加的方法(showAndHide)
- easyui menu 添加hideItem/showItem 方法
- Fragment hide,show方法后,会调用什么方法
- FragmentTransaction的add(),hide(),show()方法与Replace()方法的比较
- Android Fragment使用hide和show方法的问题
- Fragment加载轮换add,show,hide,replace方法
- Fragment hide/show 切换 走的方法onHiddenChanged(boolean hidden)
- 4.2.1: jQuery动画之show()方法和hide()方法
- jquery 显示隐藏div方法show(),hide(),toggle(),slideDown()总结
- [JQ权威指南]第十七天:show()与hide()方法
- 安卓中用show()和hide()方法来代替转跳fragment的replace()方法
- Jquery中使用show()与hide()方法动画显示和隐藏图片
- [JQ权威指南]第十八天:使用show()与hide()方法动画显示和隐藏图片
- FragmentTransition replace add show hide方法的使用和差异
- Android 使用hide()和show()方法切换Fragment时的问题
- Android 使用反射调用Hide方法setShowSoftInputOnFocus
- JQuery 支持 hide 和 show 事件的方法与分析
- hide和show方法实现fragment切换且不重新实例化
- [转]Android fragment 重叠问题——通过hide,show方式导致的解决方法
- 页面内容的隐藏和显示-hide()方法和show()方法