首页 > 网站 > WEB开发 > 正文

经常会用到的js函数

2024-04-27 14:14:52
字体:
来源:转载
供稿:网友

经常会用到的js函数

//获取样式function getStyle(obj,attr){if(obj.currentStyle){return obj.currentStyle[attr];}else{return getComputedStyle(obj)[attr];}}

//绑定事件function addHandler(element,type,handler){if(element.addEventListener){element.addEventListener(type,handler,false);}else if(element.attachEvent){element.attachEvent("on"+type,handler);}else{element["on"+type]=handler;}}

//取消绑定事件function removeHandler(element,type,handler){if(element.removeEventListener){element.removeEventListener(type,handler,false);}else if(element.detachEvent){element.detachEvent("on"+type,handler);}else{element["on"+type]=null;}}function getById(id){id=id+"";return document.getElementById(id);}

function getByClass(obj,className){var a=new Array;var b=obj.getElementsByTagName("*");for(var i in b){if(b[i].className==className){a.push(b[i]);}}return a;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表