Home > Web Front-end > JS Tutorial > Some commonly used Javascript functions_javascript skills

Some commonly used Javascript functions_javascript skills

WBOY
Release: 2016-05-16 19:22:55
Original
961 people have browsed it

After coming to the company, the project team I worked in developed a client-side software, and the software interface used a WEB interface, so a lot of Javascript was used. After joining the company, the project team developed a client-side software, and the software interface used WEB interface to reflect, so a lot of Javascript is used. I have sorted out some common JS functions I wrote:)

/*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 Ob(o){//Get an object
return document.getElementById(o)?document.getElementById(o):o;
}

function IsSubStr(p,s){ //Determine whether 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 for multiple buttons sharing the same form, where: o is the ID of the form b is the ID of the hidden input (its value is provided later to determine the user submission action type) s is the user submission Action type
Ob(b).value=s;
Ob(o).submit();
}

function ExChgCls(o,a,b){//Switch object className
o.className=o.className==a?b:a;
}

function ExChgHtml(o,a,b){//Switch innerHTML of the object
o .innerHTML=o.innerHTML==a?b:a;
}

function Oh(o,s){ //Output a 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;
}

/*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; iiif(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; iiif(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 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[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[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 case 1 :
 return (n0>=n1 && n0 case 2 :
 return (n0>n1 && n0<=n2);
 default :
 return (n0>=n1 && n0<=n2);
 } 
}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template