일반적으로 사용되는 javascript static class_javascript 기술 공유

WBOY
풀어 주다: 2016-05-16 16:22:52
원래의
1204명이 탐색했습니다.

더 이상 고민하지 말고 코드를 건네드리겠습니다. 용도를 아는 친구는 가져가셔도 됩니다.

코드 복사 코드는 다음과 같습니다.

유틸리티=함수(){
    반환 {
        $:함수(ID){
            return document.getElementById(id);
        },
        트림:함수(str){
            return str.replace(/(^s )|(s $)/g, "");
        },
        len:함수(str){  
            return str.replace(/[^x00-xff]/g,'**').length;  
        },
        형식:함수(str){
            var arg = 인수;
            return str.replace(/{(d )}/g, function(m, i){
                return arg[parseInt(i) 1];
            });
        },
        각각:함수(객체, 콜백, 인수){
            var 이름, i = 0, 길이 = object.length;
            if (args) {
                if ( 길이 === 정의되지 않음 ) {
                    for(객체의 이름)
                        if ( callback.apply( object[ name ], args ) === false )
                            휴식;
                } 그 외
                    for ( ; i                         if ( callback.apply( object[ i ], args ) === false )
                            휴식;
            } 그 밖의 {
                if ( 길이 === 정의되지 않음 ) {
                    for(객체의 이름)
                        if ( callback.call( 객체[ 이름 ], 이름, 객체[ 이름 ] ) === false )
                            휴식;
                } 그 외
                    for ( var 값 = 객체[0];
                        나는 < length && callback.call( value, i, value ) !== false; 값 = 객체[ i] ){}
            }
        },
        setCookie:함수(이름,값,시간,경로,도메인){
            var str=new String();
            var nextTime=new Date();
            nextTime.setHours(nextTime.getHours()시간);
            str=name "=" 이스케이프(값);
            if(시간)
                str =";expires=" nextTime.toGMTString();
            if(경로)
                str =";path=" 경로;
            if(도메인)
                str =";도메인="도메인;
            document.cookie=str;
        },
        getCookie:함수(이름){
            var rs=new RegExp("(^|)" name "=([^;]*)(;|$)","gi").exec(document.cookie),tmp;
            if(tmp=rs)
                unescape(tmp[2])를 반환합니다.
            null을 반환합니다.
        },
        delCookie:함수(이름){
            document.cookie = 이름 "=-1" "; 만료=1999년 12월 31일 금요일 23:59:59 GMT;";
        },
        /**
        *URL 문자열
        *parms 문자열
        *메서드 문자열 기본값 "get"
        *asy 부울 기본값 true
        *성공 함수(http_request.responseText)
        **/
        아약스:함수(구성){
            var url=config.url,
                parms=(config.parms?config.parms:"") "&t=" new Date().getTime(),
                method=config.method||"get",
                asy=true;
            var http_request=null;
            if(method.toLowerCase()=="get"){
                url=url "?" parms;
                parms=null;
            }
            //开始初始化XMLHttpRequest对象
            if(window.XMLHttpRequest) { //Mozilla 浏览器
                http_request = 새로운 XMLHttpRequest();
                if (http_request.overrideMimeType) {//设置MiME类别
                    http_request.overrideMimeType("text/xml");
                }
            } else if (window.ActiveXObject) { // IE浏览器
                시도해보세요 {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } 잡기 (e) {
                    {               
을 시도해 보세요.                         http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } 잡기 (e) {}
                }
            }
                 if(!http_request) { // 예외, 객체 인스턴스 생성 실패
                     새로운 오류 발생("XMLHttpRequest 개체 인스턴스를 생성할 수 없습니다.");
                    null 반환;
            }
                   http_request.open(method,url,asy);
                   http_request.onreadystatechange=function(){
If (http_request.readyState == 4){
                   시도해 보세요{
If (http_request.status == 200){
구성.성공(http_request.Responsetext)
|                      }잡기(e){
throw new Error("데이터 읽기에 실패했습니다.");
                 }
                }
            };
If(method.toLowerCase()=="post"){
                    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }
                  http_request.send(parms);
}
};
}();

꽤 괜찮지 않나요? 어쨌든 매우 만족스럽습니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!