Some common JavaScript functions _javascript techniques

Source: Internet
Author: User

The project team after the company to develop a client software, software interface with the Web interface to reflect, So there's a lot of JavaScript to use. After coming to the company, the project team developed a client-side software that uses a Web interface to represent the software, so it uses a lot of JavaScript. Write some of the general JS functions of the following:

/* Judge 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= (&& IE)? True:false;
var ns6= (&& (navigator.appname== "Netscape")? True:false;
var op8= (Navigator.userAgent.toLowerCase (). IndexOf ("opera") ==-1)? False:true;

function Ob (o) {//Get an Object
return document.getElementById (o) document.getElementById (o): o;
}

function Issubstr (p,s) {//Determine whether to be 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 for multiple buttons to share the same form, where: O is the ID of the hidden input for the form's ID B (whose value is then judged by the user-submitted action type) s to submit the action type for the user
Ob (b). Value=s;
Ob (O). Submit ();
}

function Exchgcls (o,a,b) {//Toggle object's ClassName
o.classname=o.classname==a?b:a;
}

function exchghtml (o,a,b) {//Toggle object's innerHTML
o.innerhtml=o.innerhtml==a?b:a;
}

function Oh (o,s) {//output string to an object
Ob (o). Innerhtml=s;
}

function Setsrc (o,s) {//change the SRC value of an IMG, IFRAME, etc object
Ob (o). Src=s;
}

/*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= "Data loading, please wait ...";
SW2 ("opmsg");
}

Include Javascript File
function Incjs (SSRC,SID) {
var ohead = document.getElementsByTagName (' head ') [0];
var oscript = document.createelement (' script ');
Oscript.type = "Text/javascript";
OSCRIPT.SRC = SSRC;
Oscript.id = SID;
if (oscript.readystate== "loaded") {Ohead.appendchild (oscript);}
}

/*move & remove*/
function Mv (a,b,n) {
var i = 0;
var f=ob (a);
var t=ob (b);
var n=n?n:0;
if (n==0) {
for (var ii=0; ii<f.options.length; ii++) {
if (f.options[ii].selected) {
var no = new Option ();
No.value = F.options[ii].value;
No.text = F.options[ii].text;
T.options[t.options.length] = no;
}
}
}
else {
for (var ii=0; ii<f.options.length; ii++) {
if (f.options[ii].selected) {
T.value + = "," +f.options[ii].value;
}
}
}
Rv (a);
}

function Rv (o) {
var o=ob (o);
for (var ii=o.options.length-1; ii>=0; ii--) {
if (o.options[ii].selected && o.options[ii]!= "") {
O.options[ii].value = "";
O.options[ii].text = "";
O.OPTIONS[II] = null;
}
}
}

function Chginp (O1,O2) {
Ob (O2). readonly= (! Ob (O1). checked);
if (Ob (O1). Checked) {
Ob (O2). Classname= "Inptxt";
Ob (O2). focus ();
} else {
Ob (O2). Classname= "InpTxt0";
}
}

/*checkbox*/
function Dochk (o,o2,s) {
This. Oldcls = S | | "";
if (O.checked==false) {
O.parentnode.parentnode.classname=this. Oldcls;
Ob ("Btnchkall"). Checked=false;
} else {
O.parentnode.parentnode.classname= "chked";
Isallchk (o2,this. OLDCLS);
}
}

function Isallchk (o,s) {
var chknums=0;
var arrobj=ob (o). getElementsByTagName ("input");
This. Oldcls = S | | "";
for (i=0;i<arrobj.length;i++) {
if (arrobj[ii].checked) {
Chknums+=1;
Arrobj[ii].parentnode.parentnode.classname= "chked";
} else {
Arrobj[ii].parentnode.parentnode.classname=this. Oldcls;
}
}
Alert (chknums+ ":" +arrobj.length)
if (chknums==arrobj.length-1) {
Ob ("Btnchkall"). Checked=true;
} else {
Ob ("Btnchkall"). Checked=false;
}
}

function Chkall (o,o2,s) {
var arrobj=ob (O2). getElementsByTagName ("input");
This. Oldcls = S | | "";
for (ii=1;ii<arrobj.length;ii++) {
arrobj[ii].checked=o.checked;
if (o.checked) {
Arrobj[ii].parentnode.parentnode.classname= "chked";
} else {
Arrobj[ii].parentnode.parentnode.classname=this. Oldcls;
}
}
}

function Oppchk () {
var arrobj=ob ("Photos"). getElementsByTagName ("input");
for (ii=0;ii<arrobj.length;ii++) {
arrobj[ii].checked=!arrobj[ii].checked;
}
Isallchk ();
}

/*test nums*/
function Isintnum (s) {
var reintnum=/^\-?\d+$/;
return Reintnum.test (s);
}
function Isbetween (n0,n1,n2,t) {
this.comparetype=t | | 4;
Switch (this.comparetype) {
Case 0:
Return (n0>n1 && n0<n2);
Case 1:
Return (n0>=n1 && n0<n2);
Case 2:
Return (n0>n1 && n0<=n2);
Default:
Return (n0>=n1 && n0<=n2);
}
}

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.