Preface
The library is a hotly debated topic. One view is that it is a great tool and indispensable to any developer, while another view is that relying on the library without understanding the internal workings of the library can encourage laziness and lead to a decline in developer quality. But no matter what, it seems that everyone agrees to write their own library, and it's a meaningful thing to combine what they use everyday.
Below we start to build our own JS library, and write two of their own methods
Copy Code code as follows:
Author:
Time: 2012-11-13
(function () {
window[' LS ']={};
function $ () {
var elements =new Array ();
var element;
for (Var i=0;i<arguments.length;i++) {
if (typeof (Arguments[i]) = = "string") {
Element=document.getelementbyid (Arguments[i]);
}
if (arguments.length==1) {
return element;
}
Elements.push (Element);
}
return elements;
}
window[' LS ' [' $ ']=$;
function Getelementbyclassname (Classname,tag) {
var alltags=document.getelementsbytagname (tag);
var matchingelements=new Array ();
Classname=classname.replace (/\-/g, "\\-"); I don't understand what this sentence means.
var regex=new RegExp ("(^|\\s) *" +classname+ "(\\s|$)");
var element;
for (Var i=0;i<alltags.length;i++) {
Element=alltags[i];
if (Regex.test (element.classname)) {//This element.classname does not understand what it means
Matchingelements.push (Element);
}
}
return matchingelements;
}
window[' LS ' [' Getelementbyclassname ']=getelementbyclassname;
} ()///If no () cannot be performed
I was just beginning to contact with JavaScript, which is part of the annotation is I do not understand the place, but also hope that the expert can guide.