个人js类库mycool
Posted sunbey80
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了个人js类库mycool相关的知识,希望对你有一定的参考价值。
// javascript Document Sunbye 1.0 //getElementById //function start var $=function(_id){return document.getElementById(_id)}; //function end //function start function byClass(classname){ if(document.getElementsByClassName){ //判断是否为火狐浏览器,也可用document.all判断是IE return document.getElementsByClassName(classname); }else{ var tags=document.getElementsByTagName("*"); var tagslength=tags.length; var gettags=[]; for(var i=0;i<tagslength;i++){ if(tags[i].className==classname){ gettags.push(tags[i]); } } return gettags; } } //function end //function start function inputSearch(tagid,prompttxt,colorfocus,colorblur){ tagid=document.getElementById(tagid); tagid.value=prompttxt; tagid.style.color=colorblur; tagid.onfocus=function(){ if(this.value==prompttxt){ this.value=""; this.style.color=colorfocus; } }; tagid.onblur=function(){ if(this.value==""){ this.value=prompttxt; tagid.style.color=colorblur; }else{ this.style.color=colorfocus; } }; } //function end //function start function fadeOut(ele,speed){ var ele=document.getElementById(ele); var opacitynum=ele.style.opacity||1; var speed=(speed/100)||10; function opacityOff(){ if(opacitynum>0){ ele.style.opacity=opacitynum=(opacitynum-0.01).toFixed(2); }else{ clearInterval(opacityt); } } var opacityt=setInterval(opacityOff,speed); } //function end //function start function fadeIn(ele,speed){ var ele=document.getElementById(ele); var opacitynum=ele.style.opacity||0; var speed=(speed/100)||10; function opacityAdd(){ if(opacitynum<1){ ele.style.opacity=opacitynum=(parseFloat(opacitynum)+0.01).toFixed(2); }else{ clearInterval(opacityt); } } var opacityt=setInterval(opacityAdd,speed); } //function end //function start function hasClass(obj,cls){ return obj.className.match(new RegExp(‘(\\s|^)‘ + cls + ‘(\\s|$)‘)); } function addClass(obj,cls){ if(!this.hasClass(obj,cls)) obj.className += " " + cls; } function removeClass(obj,cls){ if(hasClass(obj,cls)) { var reg=new RegExp(‘(\\s|^)‘+cls+‘(\\s|$)‘); obj.className=obj.className.replace(reg,‘ ‘); } } //function end
以上是关于个人js类库mycool的主要内容,如果未能解决你的问题,请参考以下文章