欢迎来到福编程网,本站提供各种互联网专业知识!

js几个不错的函数 $$()

发布时间:2006-10-09 作者: 来源:转载
复制代码代码如下:functionmap(a,f){f(a);}functiongetRand(a,b){if(a){b=b?b:0;returnMath.floor(Math.random()*a+b);}else{a=newDate();returnd.getTime();}}function$(a){document.write(a);}function$$(){varelements=newArray();for(vari=0;i0){
复制代码 代码如下:
functionmap(a,f){f(a);}
functiongetRand(a,b)
{
if(a)
{
b=b?b:0;
returnMath.floor(Math.random()*a+b);
}else
{
a=newDate();
returnd.getTime();
}
}
function$(a){document.write(a);}
function$$()
{
varelements=newArray();
for(vari=0;i{
varelement=arguments[i];
if(typeofelement=='string')
element=document.getElementById(element);

if(arguments.length==1)
returnelement;

elements.push(element);
}
returnelements;
}
functionfGetCookie(name)
{
varcookieValue="";
varsearch=name+"=";
if(document.cookie.length>0)
{
offset=document.cookie.indexOf(search);
if(offset!=-1)
{
offset+=search.length;
end=document.cookie.indexOf(";",offset);
if(end==-1)end=document.cookie.length;
cookieValue=unescape(document.cookie.substring(offset,end));
}
}
returncookieValue;
}
functionJ_get(name)
{
varjs_get=self.window.document.location.href;
varstart=js_get.indexOf(name+'=');
if(start==-1)return'';
varlen=start+name.length+1;
varend=js_get.indexOf('&',len);
if(end==-1)end=js_get.length;
returnunescape(js_get.substring(len,end));
}
functionwriteCookie(name,value,hours)
{
varexpire="";
vardomain=";domain=jb51.net;path=/";
if(hours!="")
{
expire=newDate((newDate()).getTime()+hours*60*60*1000);
expire=";expires="+expire.toGMTString();
}
document.cookie=name+"="+escape(value)+domain;
}
functioncreateXMLHttp()
{
varret=null;
try{
ret=newActiveXObject('Msxml2.XMLHTTP');
}
catch(e){
try{
ret=newActiveXObject('Microsoft.XMLHTTP');
}
catch(ee){
ret=null;
}
}
if(!ret&&typeofXMLHttpRequest!='undefined')
ret=newXMLHttpRequest();
returnret;
}
functionloadXmlToElement(fragment_url,element_id,mode,de)
{
varelement=$$(element_id);
varxmlhttp=createXMLHttp();
varstr;
xmlhttp.open("GET",fragment_url);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
if(!mode)
{
str=xmlhttp.responseXML.getElementsByTagName("data")[0].childNodes[0].nodeValue;
if(!element.innerHTML)
{
try{
str=xmlhttp.responseXML.firstChild.childNodes[1].nodeValue;
}catch(e){}
}
}elseif(mode=='txt')
{
str=xmlhttp.responseText;
}
if(de)str=unescape(str);
element.innerHTML=str;
}
}
xmlhttp.send(null);
}
varoJson=newObject();
varfJson=
{
"data":{},//[0,y,yes,空值]:默认,[-1,n,no]:不运行flush(),
"file":{},//附加js代码文件
"str":{},//附加JS代码
"set":function(element,vars)
{
for(keyinvars)
{
this[key][element]=vars[key];
}
},
"getSrc":function(element)
{
varrs='';
if(this['data'][element])
{
if(this['data'][element]=='n'||this['data'][element]=='-1'||this['data'][element]=='no')
{
rs+='&gJsonData=n';
}
}
if(this['str'][element])
{
rs+='&gJsonDoStr='+escape(this['str'][element]);
}
if(this['file'][element])
{
rs+='&gJsonDoFile='+escape(this['file'][element]);
}
returnrs;
},
"main":function(url,element,un)
{
un=un?un:0;
eval("oJson."+element+"=newfJson.__Json('"+url+"','"+element+"','"+un+"')");
},
"__Json":function(url,element,un)
{
vara=document.getElementById("script_"+element)
if(!a)
{
a=document.createElement("script");
a.setAttribute("id","script_"+element);
}
a.un=un;
a.data='';
a.src=url+((url.indexOf('?')==-1)?'?':'&')+'gJson='+element+fJson.getSrc(element);
if(navigator.appVersion.indexOf("MSIE")==-1)
{
document.getElementById(element).insertBefore(a,null);
}else
{
document.body.insertAdjacentElement("BeforeBegin",a);
}
returna;
},
"flush":function(element)
{
document.getElementById(element).innerHTML=(oJson[element].un)?unescape(oJson[element].data):oJson[element].data;
//oJson[element]=null;
}
}
/*应用*/
functionsubPageSelect(b,e,d,a)//b开始e结束d默认a动作
{
varshtml='<select'+a+'>';
for(vari=b;i<=e;i++)
{
shtml+=''+i+'';
}
shtml+='';
returnshtml;
}
functionerr(a,b,c)
{
if(b)
{
if(c)
{
a.src='http://www.jb51.net/space/imgs/all/thu_woman.gif';
}else
{
a.src='http://v.jb51.net:88/img/user_no_photo.gif';
}
}else
{
a.src='http://v.jb51.net:88/img/flv_no_photo.gif';
}
}
functionimg_onerr(a)
{
err(a);
}
functiongowin(a)
{
document.location=a;
}
functionCopyInBoard(hahaUrl,note)
{
note=note?note:'网址复制成功啦!';
window.clipboardData.setData('text',hahaUrl)
alert(note);
}
functionfDoMask(a,f,s,c,p,color)//a元素f刷新调函数s样式c内容p透明度
{
a=$$(a);
p=p?p:75;
s=''+(c?c:'数据加载中...')+(f?'[刷新]':'')+'

';
color=color?color:'#FFFFFF';
if(a.innerHTML!="")
{
//window.onunload=fCheckStatus;
varobjBrother=a.childNodes[0];
varb=document.createElement('DIV');
b.setAttribute('id','maskdiv');
b.style.textAlign="center";
b.style.position="absolute";
b.style.filter="alpha(opacity="+p+")";
b.style.opacity=(p/100);
b.style.MozOpacity=(p/100);
b.style.KhtmlOpacity=(p/100);
b.style.width=a['offsetWidth']+'px';
b.style.height=a['offsetHeight']+'px';
b.style.margin="0px";
b.style.backgroundColor=color;
a.insertBefore(b,objBrother)
b.innerHTML=s;
}
}
functionswitchDisplay(obj1,obj2)
{
try
{
obj1=$$(obj1);
obj2=$$(obj2);
if(obj1.style.display=='')
{
obj1.style.display='none';
obj2.style.display='';
}
else
{
obj1.style.display='';
obj2.style.display='none';
}
}catch(ex)
{
}
}
functiongetFlashPlayer(vars,playUrl,id,w,h)
{
playUrl=playUrl?playUrl:'http://www.jb51.net/flashApp/56';
id=id?id:'siteFlvPlayer';
w=w?w:'440';
h=h?h:'371';
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width',w,'height',h,'id',id,'src',playUrl,'flashvars',vars,'quality','high','scale','noscale','wmode','transparent','name',id,'salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',playUrl);//endACcode
}
functionf_js_playObject(a,h,s,player)
{
h='www.jb51.net';//#..
player=player?player:'/flashApp/v_player_site_fp7_5.swf';
player='http://'+h+player;
s=s?s:'width="100%"height="100%"';

var_into="";
_into+='';
_into+='双击播放器屏幕或者点“全屏”可取消或恢复全屏

';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='';
_into+='
';
_into+='
';
_into+='';
_into+='如果不能正常播放,请点此查看详情';
_into+='因以下情况,导致视频无法正常播放,请下载Flash8.0播放器。点此下载

1.如果打开页面只有声音没有视频画面

2.播放器无法加载,出现“红X”

3.播放器可以加载,但提示版本过低!

非上述情况下出现无法播放时,请给我们反映!点此报告

[关闭详情]';

document.getElementById('js_playObject').innerHTML=_into;
FcheckZoom();
}
functionzoomMovie(){
varobjId='videoPlayer';
varvideoObject=document.all?document.all[objId]:document.getElementById(objId);
varmaskForIe=document.all?document.all['maskForIe']:document.getElementById('maskForIe');
varvideoPlayBack=document.all?document.all['flvPlayBack']:document.getElementById('flvPlayBack');
varplayerInfo=document.all?document.all['PlayerInfo']:document.getElementById('PlayerInfo');
varsearchBox=document.all?document.all['nav_search_form']:document.getElementById('nav_search_form');
varisMaxmized=/.*maxmized.*/i.test(videoObject.className);
if(isMaxmized){
videoObject.className='normalSize';
videoObject.style.position='';
videoPlayBack.firstChild.BGCOLOR='ffffff';
playerInfo.style.display='none';
maskForIe.style.display='none';
searchBox.style.display='';
}else{
window.scrollTo(0,0);
videoObject.className='maxmized';
videoObject.style.position='absolute';
if(navigator.appName.lastIndexOf('Explorer')!=-1){
videoObject.style.left=(document.body.parentNode.scrollWidth-600)/2;
videoObject.style.top='30';
playerInfo.style.display='';
maskForIe.style.display='';
}
videoPlayBack.firstChild.BGCOLOR='000000';
}
videoObject.onclick=function(){zoomMovie()}
}
functionFcheckZoom()
{
vara=J_get('fs');
if(a==1)
{
zoomMovie();
}
}
/*菜单*/
varisOverMainMenu=false;
varisOverSortMenu=false;
functionshowMenu(id){
vara=document.getElementById("MainMenu").getElementsByTagName("a");
for(vari=0;ia[i].onmouseover=function(){
if(this.className!="active")this.className="hover";
showSortMenu(this.id);
isOverMainMenu=true;
}
a[i].onmouseout=function(){
if(this.className!="active")this.className="";
setTimeout("showSortMenu('"+id+"')",400);
isOverMainMenu=false;
}

if(a[i].id==id){
a[i].className="active";
showSortMenu(id);
}else{
a[i].className="";
}
}
}
functionshowSortMenu(id){
vara=document.getElementById("SortMenu");
a.onmouseover=function(){
isOverSortMenu=true;
}
a.onmouseout=function(){
isOverSortMenu=false;
}
if(!isOverSortMenu&&!isOverMainMenu){
varb=document.getElementById("SortMenu").getElementsByTagName("ul");
for(vari=0;iif(b[i].id=="SortMenu_"+id){
b[i].className="active";
}else{
b[i].className="";
}
}
}
}
/*******************************/
vargLoginId=fGetCookie("member_id");//登录用户ID
vargLoginHost=fGetCookie("host");//登录主机名
vargLoginPass=fGetCookie("pass_hex");//pass
vargLoginMember=fGetCookie("member_login");//member_login
vargNewMail=fGetCookie("newmail");//新邮件
vargKeepMail=fGetCookie("keepmail");//是否检查邮件的标示
vargLoginUser=gLoginId.substring(0,gLoginId.indexOf("@"));//登录用户名
vargIsLogin=(gLoginHost!=""&&gLoginUser!=""&&gLoginPass!=""&&gLoginMember!="")?true:false;//是否已经登录
varbasedir='http://v.jb51.net:88/photo/';
varuserDir=fCaculateUrl(gLoginUser);
functionfIsLogin()
{
return(fGetCookie("host")!=""&&fGetCookie("member_id")!=""&&fGetCookie("pass_hex")!=""&&fGetCookie("member_login")!="")?true:false;
}
functionfCaculateUrl(userName)
{
varlevel1=0;
varlevel2=0;
vark=userName.length;
//vararr=newArray();
for(vari=0;i{
level1+=userName.charCodeAt(i)*i;
level2+=userName.charCodeAt(i)*(2*i+1);
}
level1=level1%100;
level2=level2%100;
returnlevel1+'/'+level2;
}
document.domain="jb51.net";
window.focus();

相关推荐