欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

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

时间:2020-10-30 16:27:00|栏目:JavaScript代码|点击:
复制代码 代码如下:

function map(a,f){f(a);}
function getRand(a,b)
{
    if(a)
    {
        b=b?b:0;
        return Math.floor(Math.random()*a+b);
    }else
    {
        a = new Date();
        return d.getTime();
    }
}
function $(a){document.write(a);}
function $$() 

    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) 
    { 
      var element = arguments[i]; 
      if (typeof element == 'string') 
        element = document.getElementById(element); 

      if (arguments.length == 1) 
        return element; 

      elements.push(element); 
    } 
    return elements; 
}
function fGetCookie(name) 
{
     var cookieValue = "";
      var search = 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));
        }
      }
      return cookieValue;
}
function J_get(name)
{
    var js_get  =self.window.document.location.href;
    var start    =js_get.indexOf(name + '=');
    if (start == -1) return '';
    var len = start + name.length + 1;
    var end = js_get.indexOf('&',len);
      if (end == -1) end = js_get.length;
      return unescape(js_get.substring(len,end));
}
function writeCookie(name, value, hours)
{
    var expire = "";
    var domain = "; domain=jb51.net; path=/";
    if(hours != "") 
    {
        expire = new Date((new Date()).getTime() + hours * 60 * 60 * 1000);
        expire = "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + domain;
}
function createXMLHttp()
{
    var ret = null;
    try {
        ret = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            ret = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (ee) {
            ret = null;
        }
    }
    if (!ret && typeof XMLHttpRequest != 'undefined')
        ret = new XMLHttpRequest();
    return ret;
}
function loadXmlToElement(fragment_url, element_id,mode,de)
{
    var element = $$(element_id);
    var xmlhttp = createXMLHttp();
    var str;
    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){}
                }
            }else if(mode == 'txt')
            {
                str = xmlhttp.responseText;
            }
            if(de) str = unescape(str);
            element.innerHTML = str;
        }
    }
    xmlhttp.send(null);    
}
var oJson = new Object();
var fJson = 
{
    "data":{},//[0,y,yes,空值]:默认,[-1,n,no]:不运行flush(),
    "file":{},//附加js代码文件
    "str":{},//附加JS代码
    "set":function(element,vars)
    {
        for(key in vars)
        {
            this[key][element] = vars[key];
        }
    },
    "getSrc":function(element)
    {
        var rs = '';
        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]);
        }
        return rs;
    },
    "main":function(url,element,un)
    {
        un = un?un:0;
        eval("oJson."+element+" = new fJson.__Json('"+url+"','"+element+"','"+un+"')" );
    },
    "__Json":function(url,element,un)
    {
        var a            = 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);    
        }
        return a;
    },
    "flush":function(element)
    {
        document.getElementById(element).innerHTML =  (oJson[element].un)?unescape(oJson[element].data):oJson[element].data;
        //oJson[element] = null;
    }    
}
/* 应用 */
function subPageSelect(b,e,d,a)//b开始 e结束 d默认 a动作

    var shtml ='<select '+a+'>';
    for(var i=b;i<=e;i++)
    {
        shtml+='<option value="'+i+'" '+(i==d?shtml+='selected':'')+'>'+i+'</option>';
    }
    shtml+='</select>';
    return shtml;
}
function err(a,b,c)
{
    if(b)
    {
        if(c)
        {
            a.src='https://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';
    }
}
function img_onerr(a)
{
    err(a);
}
function gowin(a)
{
    document.location = a;    
}
function CopyInBoard(hahaUrl,note) 
{             
    note    = note?note:'网址复制成功啦!';
    window.clipboardData.setData('text',hahaUrl)
    alert(note);            
}
function fDoMask(a,f,s,c,p,color)//a元素  f刷新调函数 s样式 c内容 p透明度

    a = $$(a);
    p = p?p:75;
    s = '<div style="'+(s?s:'text-align:center; margin-top:40px;')+'">'+(c?c:'<img src="https://www.jb51.net/space/imgs/all/loading.gif"  border="0"/> 数据加载中... ')+(f?'[<a href="javascript:'+f+'">刷新</a>]':'')+'</div>';
    color = color?color:'#FFFFFF';
    if (a.innerHTML != "")
    {
        //window.onunload = fCheckStatus;
        var objBrother = a.childNodes[0];
        var b = 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;
    }
}
function switchDisplay(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)
    {
    }
}
function getFlashPlayer(vars,playUrl,id,w,h)
{
    playUrl = playUrl?playUrl:'https://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); //end AC code
}
function f_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 += '<div id="videoPlayer">';
    _into += '<div id="PlayerInfo" style="color:#ffffff;font-weight:bold;text-align:center;display:none;">双击播放器屏幕或者点“全屏”可取消或恢复全屏</div>';
    _into += '<div id="flvPlayBack" class="normalSize">';
    _into += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+s+'>';
    _into += '<param name="allowScriptAccess" value="always" />';
    _into += '<param name="movie" value="'+player+'" />';
    _into += '<param name="quality" value="high" />';
    _into += '<param name="bgcolor" value="#ffffff" />';
    _into += '<param name="FlashVars" value="&'+a+'" />';
    _into += '<embed src="'+player+'" flashvars="&'+a+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"  align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" '+s+'>';
    _into += '</embed>';
    _into += '</object>'    ;
    _into += '</div></div>';
    _into += '<div id="maskForIe" style="lexrus:expression(this.style.width=document.body.parentNode.scrollWidth);aether:expression(this.style.height=document.body.parentNode.scrollHeight);display:none;background:#000;filter:alpha(opacity=70);position:absolute !important;left:0;top:0;width:100% !important;"></div>';
    _into += '<style>#videoPlayer{margin:0;padding:0 !important;width:440px;height:371px;}#program_player td{padding:0 !important;}';
    _into += '.maxmized{z-index:9999;margin:0;padding:0;position:absolute;left:0;top:0;width:100% !important;height:100% !important;filter:alpha(opacity=70);}';
    _into += '.maxmized #flvPlayBack{width:580px !important;height:490px !important;}';
    _into += '.maxmized #PlayerInfo{width:580px !important;}';
    _into += '.normalSize{width:440px;height:371px;}#flvPlayBack{margin:auto;height:100%;}#PlayerInfo{width:440px;}</style>';
    _into += '<div style="text-align:center;margin-top:7px;margin-bottom:-8px;color:gray;" id="playerInfo1">如果不能正常播放,请点此<a href="javascript:void(0);" onClick="switchDisplay(\'playerInfo1\', \'playerInfo2\');">查看详情</a></div>';
    _into += '<div style="background:#fffbee;border:2px solid #EDBB17;margin-right:4px;margin-top:7px;margin-bottom:-8px;padding:12px;display:none" id="playerInfo2">因以下情况,导致视频无法正常播放,请下载Flash8.0播放器。<a href="http://v.jb51.net/flashApp/Flash_AX80.exe">点此下载</a><br>1.如果打开页面只有声音没有视频画面<br>2.播放器无法加载,出现“红X”<br>3.播放器可以加载,但提示版本过低!<br><br>非上述情况下出现无法播放时,请给我们反映!<a href="http://bbs.jb51.net/view.html?url=http://bbs.jb51.net/data/841/841800.html?sid=11212" target="_blank">点此报告</a><br><br>[<a href="javascript:void(0);" onClick="switchDisplay(\'playerInfo1\', \'playerInfo2\');">关闭详情</a>]</div>';

    document.getElementById('js_playObject').innerHTML = _into;
    FcheckZoom();
}
function zoomMovie(){
    var objId='videoPlayer';
    var videoObject=document.all?document.all[objId]:document.getElementById(objId);
    var maskForIe=document.all?document.all['maskForIe']:document.getElementById('maskForIe');
    var videoPlayBack=document.all?document.all['flvPlayBack']:document.getElementById('flvPlayBack');
    var playerInfo=document.all?document.all['PlayerInfo']:document.getElementById('PlayerInfo');
    var searchBox=document.all?document.all['nav_search_form']:document.getElementById('nav_search_form');
    var isMaxmized=/.*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()}
}
function FcheckZoom()
{
    var a = J_get('fs');
    if (a==1)
    {
        zoomMovie();
    }
}
/* 菜单 */
var isOverMainMenu = false;
var isOverSortMenu = false;
function showMenu(id){
    var a = document.getElementById("MainMenu").getElementsByTagName("a");
    for(var i=0;i<a.length;i++){
        a[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 = "";
        }
    }
}
function showSortMenu(id){
    var a = document.getElementById("SortMenu");
    a.onmouseover = function(){
        isOverSortMenu=true;
    }
    a.onmouseout = function(){
        isOverSortMenu=false;
    }
    if(!isOverSortMenu && !isOverMainMenu) {
        var b = document.getElementById("SortMenu").getElementsByTagName("ul"); 
        for(var i=0;i<b.length;i++){
            if(b[i].id == "SortMenu_"+id) {
                b[i].className = "active";
            } else {
                b[i].className = "";
            }
        }
    }
}
/*******************************/
var gLoginId             = fGetCookie("member_id");                                            //登录用户ID
var gLoginHost         = fGetCookie("host");                                                //登录主机名
var gLoginPass         = fGetCookie("pass_hex");                                            //pass
var gLoginMember     = fGetCookie("member_login");                                        //member_login
var gNewMail             = fGetCookie("newmail");                                            //新邮件
var gKeepMail         = fGetCookie("keepmail");                                            //是否检查邮件的标示
var gLoginUser         = gLoginId.substring(0,gLoginId.indexOf("@"));                        //登录用户名
var gIsLogin             = (gLoginHost != "" && gLoginUser != "" && gLoginPass !="" && gLoginMember != "")?true:false; //是否已经登录
var basedir                = 'http://v.jb51.net:88/photo/';
var userDir             = fCaculateUrl(gLoginUser);
function fIsLogin()
{
    return (fGetCookie("host") != "" && fGetCookie("member_id") != "" && fGetCookie("pass_hex") !="" && fGetCookie("member_login") != "")?true:false;
}
function fCaculateUrl(userName)
{
    var level1 = 0;
    var level2 = 0;
    var k = userName.length;
    //var arr = new Array();
    for(var i=0;i<k;i++)
    {
        level1 += userName.charCodeAt(i)*i;
        level2 += userName.charCodeAt(i)*(2*i+1);
    }
    level1 = level1 % 100;
    level2 = level2 % 100; 
    return level1+'/'+level2;
}
document.domain        = "jb51.net";
window.focus();

上一篇:Javascript实现获取及设置光标位置的方法

栏    目:JavaScript代码

下一篇:JS forEach跳出循环2种实现方法

本文标题:js几个不错的函数 $$()

本文地址:http://www.codeinn.net/misctech/17452.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有