>  기사  >  웹 프론트엔드  >  몇 가지 좋은 js 함수 $$()_javascript 기술

몇 가지 좋은 js 함수 $$()_javascript 기술

WBOY
WBOY원래의
2016-05-16 19:25:281199검색
코드 복사 코드는 다음과 같습니다.

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

    var elements = new Array();
    for (var i = 0; i     { 
      var 요소 = arguments[i]; 
      if (요소 유형 == '문자열') 
        요소 = document.getElementById(element); 

      if (arguments.length == 1) 
        return 요소; 

      elements.push(element); 
    } 
    요소를 반환합니다. 
}
함수 fGetCookie(이름) 
{
     var cookieValue = "";
      var 검색 = 이름   "=";
      if(document.cookie.length > 0) 
    { 
        offset = document.cookie.indexOf(search);
        if (오프셋 != -1) 
        { 
              오프셋  = search.length;
              end = document.cookie.indexOf(";", offset);
              if (end == -1) end = document.cookie.length;
              cookieValue = unescape(document.cookie.substring(offset, end));
        }
      }
      return cookieValue;
}
함수 J_get(이름)
{
    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));
}
함수 writeCookie(이름, 값, 시간)
{
    var expire = "";
    var domain = "; domain=jb51.net; path=/";
    if(시간 != "") 
    {
        expire = new Date((new Date()).getTime()   시간 * 60 * 60 * 1000);
        expire = "; expires="   expire.toGMTString();
    }
    document.cookie = 이름   "="   escape(값)   domain;
}
함수 createXMLHttp()
{
    var ret = null;
    시도해 보세요 {
        ret = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(e) {
        시도 {
            ret = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (ee) {
            ret = null;
        }
    }
    if (!ret && typeof XMLHttpRequest != '정의되지 않음')
        ret = new XMLHttpRequest();
    반품 복귀;
}
함수 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)
               {
                 시도{
                      str = xmlhttp.responseX ML.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(),
    "파일":{},//附加js代码文件
    "str":{},//附加JS代码
    "set":function(element,vars)
    {
        for(키 입력 변수)
        {
            this[key][element] = vars[key];
        }
    },
    "getSrc":function(element)
    {
        var rs = '';
        if(this['data'][요소])
        {
            if(this['data'][요소] == 'n' || this['data'][요소] = = '-1' ||  this['data'][요소] == '아니요')
            {
              rs  ='&gJsonData=n';
            }
        }
        if(this['str'][element])
        {
            rs  ='&gJsonDoStr=' escape(this['str'][element]);
        }
        if(this['file'][element])
        {
            rs  ='&gJsonDoFile=' escape(this['file'][element]);
        }
        반품 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_" 요소)
        if(!a)
{
            a            = document.createElement("script");
            a.setAttribute("id","script_" 요소);
        }
        a.un            = un;
        a.data             = '';
        a.src            = url ((url.indexOf('?') == -1 )?'?':'&') 'gJson=' 요소 fJson.getSrc(element);
        if(navigator.appVersion.indexOf("MSIE") == -1 )
        {
           document.getElementById(element).insertBefore(a,null);
        }else
        {
            document.body.insertAdjacentElement("BeforeBegin",a);    
        }
        반환 a;
    },
    "flush":function(element)
    {
        document.getElementById(element).innerHTML =  (oJson[element].un)?unescape(oJson[element].data) :oJson[요소].data;
        //oJson[요소] = null;
    }    
}
/* 应用 */
함수 subPageSelect(b,e,d,a)//b开始 e结束 d默认 a动작

    var shtml = '<선택 ' '>';
    for(var i=b;i<=e;i )
    {
        shtml ='' 나는 '';
    }
    shtml ='';
    shtml을 반환합니다.
}
함수 오류(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';
    }
}
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 = '
'+(c?c:' 数据加载中... ')+(f?'[刷新]':'')+'
';
    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:'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); //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 += '
';
    _into += '';
    _into += '
';
    _into += '';
    _into += '';
    _into += '';
    _into += '';
    _into += '';
    _into += '';
    _into += '';
    _into += '';
    _into += '
'    ;
    _into += '
';
    _into += '';
    _into += '';
    _into += '
如果不能正常播放,请点此查看详情
';
    _into += '';

    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[i].onmouseover = function() {
           if(this.className!="active") this.className = "호버";
            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 = "활성";
            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            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");                                            //
전달 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);
함수 fIsLogin()
{
    return (fGetCookie("host") != "" && fGetCookie("member_id") != "" && fGetCookie("pass_hex") !="" && fGetCookie ("member_login") != "")?true:false;
}
함수 fCaculateUrl(userName)
{
    var level1 = 0;
    var level2 = 0;
    var k = userName.length;
    //var arr = new Array();
    for(var i=0;i    {
        level1  = userName.charCodeAt(i)*i;
        level2  = userName.charCodeAt(i)*(2*i 1);
    }
    레벨1 = 레벨1 % 100;
    레벨2 = 레벨2 % 100; 
    레벨1 '/' 레벨2를 반환합니다.
}
document.domain        = "jb51.net";
window.focus();
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.