"One" Add a listener event
Copy Code code as follows:
addhandler:function (NODE,TYPE,FN) {if ( Node.addeventlistener) {
Node.addeventlistener (Type,fn,false); //False, set to bubbling event
}
else{
node.attachevent (' On ' +type,function () {
fn.apply (node,arguments); In the Attachevent method, this does not point to node, so you need to use the Apply () method to change the
});
}
}
"Two" sets the style of an element
Copy Code code as follows:
Setcss:function (Node,val) {//val:{' top ': ' 2px ', ' font-size ': ' 12px '}
For (Var v. in Val) {
Node.style.cssText + = '; ' + V + ': ' +val[v]; With Csstext you can set multiple properties at the same time, there is a benefit to avoid cssfloat,stylefloat judgment
}
}
"Three" gets the CSS class name element
Copy Code code as follows:
Parent is an optional parameter,
Getbyclassname:function (classname,parent) {
var elem = [],
node = parent!= undefined&&parent.nodetype==1?parent.getelementsbytagname (' * '): document.getElementsByTagName (' * '),
p = new RegExp ("(^|\\s)" +classname+ "(\\s|$)");
for (Var n=0,i=node.length;n<i;n++) {
if (P.test (Node[n].classname)) {
Elem.push (Node[n]);
}
}
return elem;
}
"Four" delete CSS class name
Copy Code code as follows:
Removeclassname:function (node,classname) {
var par = new RegExp (className, ' G ');
Node.classname = Node.className.replace (par, ');
}
The above 4 is I tidy very practical also need to often use the original JS function, recommended to the small partners, I hope to help.