Getelementsbyclassname ()
To read a large number of HTML Code To find out the tree menu (maybe there are multiple), let's first implement a method to find the DOM node through classname: getelementsbyclassname. This is a simple but practical extension of the browser's own DOM method.
This method has two parameters: ele indicates which Dom node is used as the root node (that is, only the child node of ELE is used ), classname indicates the type of classname that must be included in the class attribute of a qualified node. Its return value is an array that stores all nodes that meet the conditions.Copy codeThe Code is as follows: function getelementsbyclassname (Ele, classname ){
// Obtain all child nodes
If (document. All ){
VaR children = ELE. All;
} Else {
VaR children = ELE. getelementsbytagname ('*');
}
// Traverse the subnode and check the classname attribute
VaR elements = new array ();
For (VAR I = 0; I <children. length; I ++ ){
VaR child = children [I];
VaR classnames = Child. classname. Split ('');
For (var j = 0; j <classnames. length; j ++ ){
If (classnames [J] = classname ){
Elements [elements. Length] = child;
Break;
}
}
}
Return elements;
}
VaR trees = getelementsbyclassname (document, 'treeview ');
The first if-else language is to be compatible with ie5 (ie5 cannot run
Document. getelementsbytagname ('*')). Note that do not use the browser detection method to write scripts. Instead, you should directly use the statements to test whether execution can be performed. If the return value is null or undefined, then another method is used. Such scripts can have better compatibility and robustness.
Elements [elements. Length] = child;
. If you must use the push method, You can execute getelementsbyclassname ()
Previously, reload the push method. The Code is as follows:
Array. Prototype. Push = function (value ){
This [This. Length] = value;
} Note: I originally hoped that getelementsbyclassname could be written like a push method, for example
Htmlelement. Prototype. getelementsbyclassname = .... However, during actual operations
The htmlelement object is not fixed during runtime, and each tag seems to be different.
Parameters in the address barCopy codeThe Code is as follows: // V1:
VaR urlparams = new array ();
VaR aparams = Document. Location. Search. substr (1). Split ('&');
For (I = 0; I <aparams. length I ++ ){
VaR aparam = aparams. Split ('= ');
Urlparams [aparam [0] = aparam [1];
}
// Obtain the passed name parameter
Name = urlparams ['name'];
// V2:
request = {
querystring: function (item) {
var svalue = location. search. match (New
Regexp ('[\? \ &] '+ Item +' = ([^ \ &] *) (\ &?) ',' I ');
return svalue? Svalue [1]: svalue;
}< BR >}< br> var key = request. querystring ('key');