<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <ptml> <pead> & Lt;meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "> <title>javascript chained call </title> <script type=" Text/javascript "> Function ele () { This.elements=[]; var element; if (typeof arguments[0]== "string") {Element=arguments[0]; if (Element.slice (0, 1) = = ' # ') {element = document.getElementById (Element.slice (1)); This.elements.push (Element); }else if (element.slice (0,1) = = '. ') {Element=element.slice (1); var es = document.body.getElementsByTagName (' * '); for (var i = 0, j = es.length I < J; i++) {if (Element.indexof (es[i].classname)!=-1) {//alert (111); This.elements.push (Es[i]); }}else{this.elements = document.getElementsByTagName (Element); alert (elements[0].id); }}else{Element=this; This.elements.push (Element); } ele.prototype.each=function (FN) {for (Var i=0,l=this.elements.length;i<l; i++) {Fn.call (this,this.elements[i]); return to this; }; Ele.prototype.setstyle=function (prop,value) {This.each (function (EL) {el.style[prop]=value; }); return this; }; Ele.prototype.show=function () {This.setstyle ("display", "block"); return this; }; Window.$=function () {return new Ele (Arguments[0]); }; </script> </pead> <body> <div id= "test" class= "TTT" ></div> <div class= "TTT" >< /div> <script type= "Text/javascript" > $ ('. TTT '). SetStyle (' width ', ' 300px '). Show (); $ (' #test '). SetStyle (' width ', ' 300px '). Show (); $ (' div '). SetStyle (' width ', ' 300px '). Show (); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]