Home  >  Article  >  Web Front-end  >  Summary of common functions in Javascript

Summary of common functions in Javascript

巴扎黑
巴扎黑Original
2017-08-10 14:02:34930browse

[Introduction] The software interface uses a WEB interface, so Javascript is used. Some common JS functions are organized:) *Determine the browser version* var w3c=(document getElementById)? true: false; var agt=navigator userAgent toLowerCase (); var ie = (

The software interface uses a WEB interface, so Javascript is used. Some common JS functions are sorted out:)

/*判断浏览器版本*/ 
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){//切换对象的className 
o.className=o.className==a?b:a; 
} 
function ExChgHtml(o,a,b){//切换对象的innerHTML 
o.innerHTML=o.innerHTML==a?b:a; 
} 
function Oh(o,s){ //输出字符串给某个对象 
Ob(o).innerHTML=s; 
} 
function SetSrc(o,s){//改变img、iframe等对象的src值 
Ob(o).src=s; 
} 
function Ob(o){//取得一个对象 
return document.getElementById(o)?document.getElementById(o):o; 
} 
function IsSubStr(p,s){//判断是否为子字符串 
return (p.indexOf(s)>-1); 
} 
function Hd(o){//隐藏某个对象 
Ob(o).style.display="none"; 
} 
function Sw(o){//显示某个对象 
Ob(o).style.display="block"; 
} 
function Sw2(o){//显示某个对象 
Ob(o).style.display=""; 
} 
function Sf(o,s,b){ 
//该函数用于多按钮共用同一表单,其中:o为表单的ID b为隐藏的input的ID(其value供后如判断用户提交动作类型) s为用户提交动作类型 
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="数据加载中,请稍候......"; 
//Sw2("OpMsg"); 
}

The above is the detailed content of Summary of common functions in Javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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