Common Javascript Functions

Source: Internet
Author: User

The software interface uses the WEB interface, so Javascript is required. Some general JS functions are sorted out below :)


/* Determine the browser version */
Var w3c = (document. getElementById )? True: false;
Var agt = navigator. userAgent. toLowerCase ();
Var ie = (agt. indexOf ("msie ")! =-1) & (agt. indexOf ("opera") =-1) & (agt. indexOf ("omniweb") =-1 ));
Var ie5 = (w3c & ie )? True: false;
Var ns6 = (w3c & (navigator. appName = "Netscape "))? True: false;
Var op8 = (navigator. userAgent. toLowerCase (). indexOf ("opera") =-1 )? False: true;
Function ExChgCls (o, a, B) {// switch the className of the object
O. className = o. className =? B:;
}
Function ExChgHtml (o, a, B) {// switch the innerHTML of the object
O. innerHTML = o. innerHTML =? B:;
}
Function Oh (o, s) {// output string to an object
Ob (o). innerHTML = s;
}
Function SetSrc (o, s) {// change the src value of img, iframe, and other objects
Ob (o). src = s;
}
Function Ob (o) {// get an object
Return document. getElementById (o )? Document. getElementById (o): o;
}
Function IsSubStr (p, s) {// determines if it is a substring
Return (p. indexOf (s)>-1 );
}
Function Hd (o) {// hide an object
Ob (o). style. display = "none ";
}
Function Sw (o) {// display an object
Ob (o). style. display = "block ";
}
Function Sw2 (o) {// display an object
Ob (o). style. display = "";
}
Function Sf (o, s, B ){
// This function is used to share the same form with multiple buttons, where: o is the ID of the Form B is the hidden input ID (the value is provided by the user to determine the type of the submitted action) s submits the action type for the user
Ob (B). value = s;
Ob (o). submit ();
}

/* XmlHttp */
Function Gp (url, o) {// GetHttpPage
Var o = Ob (o );
Var PageRequest = false;
IsLoading (o );
If (window. XMLHttpRequest) {// if Mozilla, Safari etc
PageRequest = new XMLHttpRequest ();
}
Else if (window. ActiveXObject) {// if IE
Try {
PageRequest = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e ){
Try {
PageRequest = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e ){;}
}
}
Else {return false ;}
PageRequest. onreadystatechange = function (){
If (PageRequest. readyState = 4 ){
Lp (PageRequest, o );
}
}
PageRequest. open ('get', url, true );
PageRequest. send (null );
}
Function Lp (PageRequest, o) {// LoadPage
If (PageRequest. readyState = 4 & (PageRequest. status = 200 | window. location. href. indexOf ("http") =-1 ))
Ob (o). innerHTML = PageRequest. responseText;
// Hd ("OpMsg ");
}
Function IsLoading (o ){
O. innerHTML = "loading data. Please wait ......";
// Sw2 ("OpMsg ");
}


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.