Simple JavaScript framework for manipulating HTML elements that are compatible with all browsers

Source: Internet
Author: User
Tags tag name

1. Take element $id based on ID name (idname)
2. The element $class (ClassName) based on the class definition returns all the array of elements defined as className in the class, or $eclass (ClassName) returns the first element
3. Take element $tag according to tag name (TagName) returns an array of all elements whose label name is TagName, or $etag (TagName) returns the first element
4. A parent-child relationship takes an element $dom (id#idname class#classname tag#tagname) returns an array of elements whose label name is className for all elements under the Idname element with the class TagName, or $ Edom (id#idname class#classname tag#tagname) returns the first element, separated by a space between each relationship, and the corresponding relationship is delimited by a well number, and the relationship can be arbitrarily ordered
5. The extracted elements will be accompanied by an extension method
A.getattr (attrname) take attribute
B.setattr (Attrname, attrValue) setting properties
C.getstyle (stylename) Take style
D.setstyle (stylename,stylevalue) Setting style
E.getval () value, if it is the value of Input,select,textarea, the other tags are taken out of the embedded HTML
F.setval (value) setting value, if the value of Input,select,textarea is set, the other label is set to the embedded HTML
G.show () display element
H.hide () Hidden elements
5.AJAX operation using Functions, Ajax (Type,url,callback,data);
A.type Submission Type
B.url Submit Address
C.callback callback function
D.data pending Data (a=1&b=2)
6.Cookie operation using function, Cookie.set (k,v,e) k name v value e valid (seconds) cookie.get (k)
? 1. File Jstools.js
var jstools = {version:1.0,author: ' Lymz ', email: ' [email protected] '};
var $id = function (ID) {
Return $extend (document.getElementById (id));
};
var $class = function (clas) {
Return $extend (Getelementsbyclassname (clas));
};
var $Eclass = function (clas) {
var t = $class (CLAS);
Return t.length > 0? T[0]: null;
};
var $tag = function (tag) {
Return $extend (document.getElementsByTagName (tag));
};
var $Etag = function (tag) {
var t = $tag (tag);
Return t.length > 0? T[0]: null;
};
var $dom = function (DOM) {
var t = dom.split (");
var p=null;
for (var i = 0,l = T.length;i < l;++ i) {
if (i > 0 &&!p)
Break
else if (i > 0 && p) {
if (p.length! = undefined)
p = p[0];
}
var tt = t[i].split (' # ');
if (tt[0] = = ' id ')
p = $id (tt[1]);
else if (tt[0] = = ' class ') {
TT[1] = tt[1].split (' | ');
if (p)
p = getelementsbyclassname (tt[1][0],p);
Else
p = $class (tt[1][0]);

if (Tt[1][1])
p = $filter (p,tt[1][1]);
} else if (tt[0] = = ' Tag ') {
TT[1] = tt[1].split (' | ');
if (p)
p = p.getelementsbytagname (tt[1][0]);
Else
p = $tag (tt[1][0]);

if (Tt[1][1])
p = $filter (p,tt[1][1]);
} else
p = null;
}
Return $extend (P);
};
var $filter = function (p,filter) {
if (p = = null)
return null;
var tt = new Array ();
if (filter.indexof (' = ')!==-1) {
var t = filter.split (' = ');
for (var i = 0,j = 0,l = P.length;i < l;++ i) {
if (P[i].getattribute (t[0]) = = T[1])
Tt[j++] = P[i];
}
} else if (Filter.indexof (' ^ ')!==-1) {
var t = filter.split (' ^ ');
for (var i = 0,j = 0,l = P.length;i < l;++ i) {
if (P[i].getattribute (T[0]). toLowerCase ()! = T[1].tolowercase ())
Tt[j++] = P[i];
}
} else {
for (var i = 0,j = 0,l = P.length;i < l;++ i) {
if (p[i].nodename.tolowercase () = = Filter.tolowercase ())
Tt[j++] = P[i];
}
}
return TT;
};
var $Edom = function (DOM) {
var t = $dom (DOM);
if (t! = null && t.length! = undefined)
return t[0];
Else
return t;
};
var $extend = function (object) {
if (!object)
return object;
var t = false;
if (object.length = = undefined) {
Object = new Array (object);
T = true;
}
for (var i = 0,l = Object.length;i < l;++ i) {
object[i].getattr = function (attr) {return this.getattribute (attr);};
object[i].setattr = function (k,v) {return this.setattribute (k,v);};
Object[i].getstyle = function (k) {return eval (' This.style. ') +K);};
Object[i].setstyle = function (k,v) {return eval (' This.style. ') +k+ ' =\ ' +v+ ');};
Object[i].getval = function () {return this.value!=undefined?this.value:this.innerhtml;};
Object[i].setval = function (v) {if (this.value!=undefined) This.value=v;else this.innerhtml=v;return true;};
Object[i].show = function () {return This.setstyle (' Display ', ' block ');};
Object[i].hide = function () {return This.setstyle (' Display ', ' none ');};
}http://www.enterdesk.com/special/meitu/?
Object.each=function (func) {Beauty chart
if (this.length = = undefined)
Object = new Array (object);
var it = null;
for (var i = 0,l = Object.length;i < l;++ i) {
it = Object[i];
Func (It,i);
}
};
Return T? OBJECT[0]: object;
};
var ajax = function (type,url,func,data) {
if (window. ActiveXObject) {
var xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
} else {
var xmlhttp=new xmlhttprequest ();
}
Xmlhttp.open (type,url,true);
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate = = 4)
if (Xmlhttp.status = = 200)
if (func) func (Xmlhttp.responsetext);
};
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (Data?data:null);
};
var cookie = {
Get:function (k) {
var t = document.cookie.split ('; ‘);
for (var i = 0,l = T.length;i < l;++ i) {
var tt = t[i].split (' = ');
if (tt[0] = = k) {
Return decodeURI (tt[1]);
}
}
return undefined;
},
Set:function (k,v,e) {
if (e) {
var d = new Date ();
D.settime (D.gettime () + (e*1000));
e = '; expires= ' +d.togmtstring ();
} else
e = ";
Document.cookie = k + ' = ' + V + E;
}
};
var getelementsbyclassname = function (c,p) {
p = p? P:document;
var arrelements = p.getelementsbytagname (' * ');
var arrreturnelements = new Array ();
c = C.replace (/\-/g, "\\-");
var oregexp = new RegExp ("(^|\\s)" + C + "(\\s|$)");
var oelement;
for (var i=0; i < arrelements.length; i++) {
Oelement = Arrelements[i];
if (Oregexp.test (Oelement.classname)) {
Arrreturnelements.push (oelement);
}
}
return arrreturnelements;
};
?

Simple JavaScript framework for manipulating HTML elements that are compatible with all browsers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.