首頁  >  文章  >  web前端  >  js jquery常用知識點匯總_javascript技巧

js jquery常用知識點匯總_javascript技巧

WBOY
WBOY原創
2016-05-16 16:11:311185瀏覽

一、jquery源碼中常見的知識點

  1.string,number型轉換的快速方式

複製程式碼 程式碼如下:

// @param s為字串,n為數字
function fn(obj){
    //轉換為String型別
    var s = obj "";
    //轉換為number型別
    var n = obj;
}

  分享一個面試範例:

//加會將其後面自動轉換成字串
"64" 4="644"
//減會將其自動轉換成數字
"64"-4=60

  2.bool型別轉換

  !!obj,將其強制轉換為bool型別

複製程式碼 程式碼如下:

alert(!!0)  //結果為false
alert(!!"33dd")  //結果為true

  !obj,取相反的bool型

複製程式碼 程式碼如下:

alert(!0)  //結果為true
alert(!"222333")  //結果為false

  3.=== 與 ==區別

  === 是嚴格相等,不會進行型別轉換,而 == 是不嚴格相等,會進行型別轉換。有些js的書中,建議開發人員永遠不要用 == 或 != 。

  但是jquery原始碼中,有用到「==」或「!=」的情況 —— 判斷 undefined 和 null 的時候。

複製程式碼 程式碼如下:

//這裡的判斷,將obj是null,obj是undefined都排除在外了
if(obj != null){
}

  4.偵測obj是否為window物件

複製程式碼 程式碼如下:

//null == window.null為true
function isWindow(obj){
    return obj != null && obj == window.obj;
}

  5.|| 與 && 用法技巧

複製程式碼 程式碼如下:

//例 var aa=5; name = aa || {} ; alert(name) 則name為55
this.name = name || {} //如果name值存在,則值為name,反之為{}
//例 var aa=5; name = aa && {} ; alert(name) 則name為{},因為aa為5,不為0則為真
this.name = bool && [] //如果bool為true,則值為[],反之則為bool

  經典實例:

複製程式碼 程式碼如下:

( window.foo || ( window.foo = "bar" ) );
                alert(window.foo);  //彈出  bar
//  為什麼最後的結果是bar呢,其實可以看成是   undefined || bar  出來的結果一定是bar

  6.setTimeout(fn,0)與setTimeout(fn)區別

  setTimeout(fn,0)與setTimeout(fn)都是延遲執行,但是setTimeout(fn)比setTimeout(fn,0)延遲時間還要長,例

複製程式碼 程式碼如下:

        function fn(){
            var data = new Date();
            for(var i=0;i                 if(i==1000){
                    console.log("fn=" data.getTime());
                }
            }
        }
        function fn1(){
            var data = new Date();
            for(var i=0;i                 if(i==1000){
                    console.log("fn1="data.getTime());
                }
            }
        }
        setTimeout(fn,0),
        setTimeout(fn1);

  結果:

  7.判斷是否為數值

複製程式碼 程式碼如下:

function isNumeric(obj){
return !isNaN(parseFloat(obj)) && isFinite(obj);
}

  8.判斷是否為空物件

複製程式碼 程式碼如下:

function isEmptyObject(){
    var name;
    //遍歷不是空物件回傳
    for (name in obj) {
        return false;
    }
    return true;
}

  9.偵測物件類型

  檢測obj物件類型,返回類型,透過Object.prototype.toString()來判斷類型,但是ie低版本相容性有問題,因此採用{}.toString來監測,返回為[object Array],[object Object],[object Function]

複製程式碼 程式碼如下:

// 類型判斷
function isType(type){
    return function(o){
        return Object.prototype.toString.call(o) === '[object ' type ']';
    }
}
var isString = isType(“String”);
var isObject = isType("Object");
var isArray = isType("Array");
isString("I'm Barret Lee.");
isArray([1,2,3]);
isObject({});

  10.jquery裡的去除空格trim妙用

複製程式碼 程式碼如下:

//相當於if (String.prototype.trim && “uFEFFxA0″.trim() !== “”)高階的瀏覽器已經支援原生的String的trim方法,但是pFan也為了避免它沒法解析全角空白,所以加多了一個判斷:」uFEFFxA0″.trim() !== “”   
vart core_version = "1.0",core_trim = core_version.trim;           
function trim(){
    core_trim && !core_trim.call("uFEFFxA0") ?
                    為 ) {
                        return text == null ?
                            "" :
                                                } :
        
                    // 進階的瀏覽器已支援原生的String的trim方法,而瀏覽器不支援則採用
                    為 ) {
                        var  whitespace = "[\x20\t\r\n\f]",
                 會                         return text == null ?
                            "" :
                            (text "").replace(rtrim, "");
                    },
                //nodeName函數是求出dom節點的節點名字或判斷其名字與傳入參數是否符合   
                nodeName: function(elem,name){
                     //IE下,且DOM節點的nodeName是大寫的,例如DIV
                     return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
;
;
;
;
;
;;

;                 } }

  11.jquery中偵測數組或類別數組中是否含存在傳入的值
複製程式碼 程式碼如下:

/**
    檢查數組中是否存在傳入的值,如果存在就回傳值所在的位置,如果不存在就回傳-1。
    *elem 規定需檢索的數值。
    *arr 陣列
    *i 可選的整數參數。規定在陣列中開始檢索的位置。它的合法取值是 0 到 arr.length - 1。如省略此參數,則將從陣列首元素開始檢索。
   */
function inArray(elem, arr, i){
    var len;
    if (arr) {
        //如果瀏覽器支援Array擁有indexOf方法
        if ([].indexOf) {
            return [].indexOf.call(arr, elem, i);
        }
        len = arr.length;
         //當i為負數的時候,由陣列後邊len i的位置開始索引
//理解這個分成兩個部分i = i ? (i         i = i ? i         for (; i             // 雙重偵測以防止類似這樣的陣列 ar = [];ar[1]=1;ar[0] = undefined; 0 in ar =false;a[0]===undefined;
            // 0 in arr  => arr[0]是否有  'nme' in arr => arr['nme']存在
            if (i in arr && arr[i] === elem) {
                return i;
            }
        }
    }
    return -1;
}

二、javascript中原型鏈常見的知識點

  1.hasOwnProperty()方法

   使用hasOwnProperty()方法可以偵測一個屬性是存在與實例,還是存在於原型中。這個方法從Object繼承,只在給定屬性存在於物件實例中時,才會回傳true。

複製程式碼 程式碼如下:

    function Person(){
            this.age=25;
            this.job="web";
    }
    Person.prototype={
        name:'pingfan',
        sayName:function(){
                        alert(this.name);
                }
    }
    var person1=new Person();
    //來自建構函數,偵測屬性,也回傳true
    alert(person1.hasOwnProperty("age"));
    //來自原型屬性,回傳false
    alert(person1.hasOwnProperty("name"));
    person1.name='ping';
    //來自實例屬性,回傳true
    alert(person1.hasOwnProperty("name"));

  2.透過instanceOf保證只實例一次

複製程式碼 程式碼如下:

 function shiCha(opt){
    //只實例一次
    if( !(this instanceof shiCha)){
        return new shiCha(opt);
    }               
}
var shicha = shiCha();

  3.javascript中Array.prototype.slice.call(arguments)  

  我們通常看到Array.prototype.slice.call(arguments,1)或Array.prototype.slice.call(arguments),都有點摸不著頭腦,其實我們就是藉助Array.prototype中slice()將arguments變成一個數組,並且使用該數組工作更方便,第二個參數是從索引值,開始將其變成數組,例Array.prototype.call("22223",2)和Array.prototype.call([ 1,2,3,4],2),從字串第二個開始。

複製程式碼 程式碼如下:

function sliArray(array){
                        //以從索引1到索引3
            return Array.prototype.slice.call(array,1,3);
}
alert(sliArray([1,2,3,4,5,6]))    //結果為2,3

  4. 利用空物件F,實現物件繼承,效率最高

複製程式碼 程式碼如下:

//利用空物件做媒介,進行繼承效果最佳
function inhert(C,P){
        var F=function(){};
        F.protototype = P.prototype;
        C.prototype = new F();
        C.prototype.constructor = C;
}

三、javascript常用方法集
  1. 常見的陣列操作方法

  數組去重:

複製程式碼 程式碼如下:

//陣列去重原型
Array.prototype.unqie = function(){
  var arr = this, len=this.length, obj={}, newArr=[];           
          while(len--){
                   if(obj[ arr[len] ] !== arr[len]){
                        obj[arr[len]] = arr[len];          obj[arr[len]] = arr[len];   newArr.push( arr[len])] = arr[len];   newArr.push( arr[len])
;                   } 
          }
return newArr.reverse();
}

  取數組中最大值:

複製程式碼 程式碼如下:

Array.prototype.arrMax=function(){
                var arr=this, len=this.length,max=arr[0];
                for(var i=1;i                         if(max                                                          }
                }
        return max;
}
//數組中透過sort取最大值
  Array.prototype.arrMax=function(){
    var arr=this;
    arr.sort(function(a,b){
      return a-b;
    })
    return arr[arr.length-1];
  }
//利用Math.max取數組最大值
Array.prototype.arrMax =function(){
    var array = this;
    return Math.max.apply(null, array);
}
alert([1,2,3,4,5,6,9,8,7,9].arrMax());

  取數組中最小值:

複製程式碼 程式碼如下:

//數組中最的小值
Array.prototype.arrMin=function(){
                var arr=this, len=this.length,min=arr[0];
                for(var i=1;i                         if(min>arr[i]){
                                                        }
                }
        return min;
}
//陣列中透過sort取最的小值
Array.prototype.arrSortMin=function(){
    var arr=this;
    arr.sort(function(a,b){
      return a-b;
    })
    return arr[0];
}
//利用Math.max取數組最大值
Array.prototype.arrSortMin =function(){
    var array = this;
    return Math.min.apply(null, array);
}
alert([1,2,3,4,5,6,9,8,7,9].arrSortMin());

  複製陣列:

複製程式碼 程式碼如下:
Array.prototype.copy =
  function() {
    return [].concat(this);
};

  去除數組中只指定元素,只能去除一個,如果想多個,之前先用unique處理:

複製程式碼 程式碼如下:
Array.prototype.remove = function(value){
    for(var i=0,len=this.length;i     {
        if(this[i]==value){
            this.splice(i, 1);
            break;
        }
    }
   
    return this;
}

  2.操作document.loaction的方法集(這裡借用了園友總結的相關方法)

複製程式碼 程式碼如下:

pFan.url = { //#URL
    //參數:變數名,url為空白則表從目前頁的url中取
    getQuery: function (name, url) {
        var u = arguments[1] || window.location.search
            , reg = new RegExp("(^|&)" name "=([^&]*)(&|$)")
            , r = u.substr(u.indexOf("?") 1).match(reg)
        ;
        return r != null ? r[2] : "";
    }
    , getHash: function (name, url) { //# 取得 hash值
        var u = arguments[1] || location.hash;
        var reg = new RegExp("(^|&)" name "=([^&]*)(&|$)");
        var r = u.substr(u.indexOf("#") 1).match(reg);
        if (r != null) {
            return r[2];
        }
        return "";
    }
    , parse: function (url) { //# 解析URL
        var a = document.createElement('a');
        url = url || document.location.href;
        a.href = url;
        return {
            source: url
            , protocol: a.protocol.replace(':', '')
            , host: a.hostname
            , port: a.port
            , query: a.search
            , file: (a.pathname.match(/([^/?#] )$/i) || [, ''])[1]
            , hash: a.hash.replace('#', '')
            , path: a.pathname.replace(/^([^/])/, '/$1')
            , relative: (a.href.match(/tps?://[^/] (. )/) || [, ''])[1]
            , segments: a.pathname.replace(/^//, '').split('/')
        };
    }
};

  3.常用的正規表示式

複製程式碼 程式碼如下:

pFan.regExp = {  //# 字串符合
    //是否為 數字!整數,浮點數
    isNum: function (num) { //# 是否為陣列
        return !isNaN(num);
    }
    , isEmail: function (mail) {//# 是否為 信箱
return /^([a-z0-9] [_-.]?)*[a-z0-9] @([a-z0-9] [_-.]?)*[a-z0-9] .[a-z]{2,5}$/i.test(mail);
    }
    , isIdCard: function (card) { //# 是否為 身分證
        return /^(d{14}|d{17})(d|[xX])$/.test(card);
    }
    , isMobile: function (mobile) { //# 是否為 手機
        return /^0*1d{10}$/.test(mobile);
    }
    , isQQ: function (qq) { //# 是否為 QQ
        return /^[1-9]d{4,10}$/.test(qq);
    }
    , isTel: function (tel) { //# 是否為 電話
        return /^d{3,4}-d{7,8}(-d{1,6})?$/.text(tel);
    }
    , isUrl: function (url) { //# 是否為 URL
        return /https?://[a-z0-9.-]{1,255}.[0-9a-z-]{1,255}/i.test(url);
    }
    , isColor: function (color) { //# 是否為 16進位顏色
        return /#([da-f]{3}){1,2}$/i.test(color);
    }
    //@id : 身分證 ,
    // @now : 目前時間 如:new Date('2013/12/12') , '2013/12/12'
    // @age : 允許的年齡
    , isAdult: function (id, allowAge, now) { //# 是否年齡是否成年
        var age = 0 // 使用者 年月日
            , nowDate = 0  //當年度月日
        ;
        allowAge = parseFloat(allowAge) || 18;
        now = typeof now == 'string' ? new Date(now) : (now || new Date());

        if (!this.isIdCard(id)) {
            return false;
        }
        //15位身分證
        if (15 == id.length) {
            age = '19' id.slice(6, 6);
        } else {
            age = id.slice(6, 14);
        }
        // 型態轉換 整數
        age = ~~age;
        nowDate = ~~(Tydic.date.format('YYYYMMDD', now));
        //比較年齡
        if (nowDate - age             return false;
        }
        return true;
    }
    //浮點數
    , isFloat: function (num) { //# 是否為 浮點數
        return /^(([1-9]d*)|(d .d )|0)$/.test(num);
    }
    //正整數
    , isInt: function (num) { //# 是否為 正整數
        return /^[1-9]d*$/.test(num);
    }
    //是否全為漢字
    , isChinese: function (str) { //# 是否皆為 漢字
        return /^([u4E00-u9FA5]|[uFE30-uFFA0]) $/gi.test(str);
    }
};

  4.操作className的方法集

複製程式碼 程式碼如下:

PFan.conClass = {
    hasClass:function(){
        return ele.className.match(new RegExp('(\s|^)' cls '(\s|$)'));
    },
    addClass:function(){
        if (!hasClass(ele,cls)) ele.className = " " cls;
    },
    removeClass:function(){
        if (hasClass(ele,cls)) {
            var reg = new RegExp('(\s|^)' cls '(\s|$)');
            ele.className=ele.className.replace(reg,' ');
        }        
    }
}

  5.操作字串方法

複製程式碼 程式碼如下:

pFan.string = { //# 字串
    codeHtml: function (content) { //# 轉義 HTML 字元
        return this.replace(content, {
            '&': "&"
            , '"': """
            , "'": '''
            , '             , '>': ">"
            , ' ': " "
            , 't': " "
            , '(': "("
            , ')': ")"
            , '*': "*"
            , ' ': "+"
            , ',': ","
            , '-': "-"
            , '.': "."
            , '/': "/"
            , '?': "?"
            , '\': "\"
            , 'n': "
"
        });
    }
    //重複字串
    , repeat: function (word, length, end) { //# 重複字串
        end = end || ''; //加在末位
        length = ~~length;
        return new Array(length * 1 1).join(word) '' end;
    }
    //增加前綴
    , addPre: function (pre, word, size) { //# 補齊。如給數字前 加 0
        pre = pre || '0';
        size = parseInt(size) || 0;
        word = String(word || '');
        var length = Math.max(0, size - word.length);
        return this.repeat(pre, length, word);
    }
    //去除兩邊空格
    , trim: function (text) { //# 去除兩邊空格
        return (text || '').replace(/^s |s$/, '');
    }
     //移除左邊空格
    ,ltrim:function(){
        return s.replace( /^(s*| *)/, "");
    }
    //移除右邊空格
    ,rtrim:function(){
        return s.replace( /(s*| *)$/, "");
    }
    //回傳腳本內容
    ,evalscript:function(s) {
        if(s.indexOf('         var p = /<script>]*?>([^x00]*?)</script>/ig;
        var arr = [];
        while(arr = p.exec(s)) {
var p1 = /<script>]*?src="([^>]*?)"[^>]*?(reload="1")?(?:charset="([w-] ? )")?></script>/i;
            var arr1 = [];
            arr1 = p1.exec(arr[0]);
            if(arr1) {
                appendscript(arr1[1], '', arr1[2], arr1[3]);
            } else {
                p1 = /<script>([^x00] ?)</script>/i;
                arr1 = p1.exec(arr[0]);
                appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
            }
        }
        return s;
    }
    //清除腳本內容
    ,stripscript:function(){
        return s.replace(/.*?/ig, '');
    }
    //字串替換
    , replace: function (str, re) { //# 字串替換
        str = str || '';
        for (var key in re) {
            replace(key, re[key]);
        };
        function replace(a, b) {
            var arr = str.split(a);
            str = arr.join(b);
        };
        return str;
    }
    , xss: function (str, type) { //# XSS 轉義
        //空過濾
        if (!str) {
            return str === 0 ? "0" : "";
        }
        switch (type) {
            case "html": //過濾html字串中的XSS
                return str.replace(/[&'"/\-x00-x09x0b-x0cx1fx80-xff]/g, function (r) {
                    return "" r.charCodeAt(0) ";"
}).replace(/ /g, " ").replace(/rn/g, "
").replace(/n/g, "
").replace(/r/g, "
");
                break;
            case "htmlEp": //過濾DOM節點屬性中的XSS
                return str.replace(/[&'"/\-x00-x1fx80-xff]/g, function (r) {
                    return "" r.charCodeAt(0) ";"
                });
                break;
            case "url": //過濾url
                return escape(str).replace(/ /g, "+");
                break;
            case "miniUrl":
                return str.replace(/%/g, "%");
                break;
            case "script":
                return str.replace(/[\"']/g, function (r) {
                    return "\" r;
}).replace(/%/g, "\x25").replace(/n/g, "\n").replace(/r/g, "\r").replace(/x01/g, "\x01");
                break;
            case "reg":
                return str.replace(/[\^$* ?{}.()[]]/g, function (a) {
                    return "\" a;
                });
                break;
            default:
                return escape(str).replace(/[&'"/\-x00-x09x0b-x0cx1fx80-xff]/g, function (rr) {
                    return "" r.charCodeAt(0) ";"
}).replace(/ /g, " ").replace(/rn/g, "
").replace(/n/g, "
").replace(/r/g, "
");
                break;
        }
    }
    // badword , 濾波敏感字
    //@text : 要過濾的文字 , 類型 :字串
    //@words : 敏感字 ,類型,陣列, 如 : ['你妹妹', '我丟' ,'我靠']
    // 如果 用 正規匹配, text 長度 100萬,words 100萬,需要 4秒!
    , badWord: function (text, words) { //# 敏感字詞過濾
        text = String(text || '');
        words = words || [];
        var reg = new RegExp(words.join('|'), 'g')
            , _self = this;
        return text.replace(reg, function ($0) {
            var length = String($0 || '').length;
            return _self.repeat('*', length);
        });
    }
};

  6.加密方法集

複製程式碼 程式碼如下:

pFan.encrypt = { //# 加密
    md5: function (words) {  //# md5 雜湊演算法
        /*
         * Crypto-JS 3.1.2
         * http://code.google.com/p/crypto-js
         */
        var CryptoJS = 函數 (s, p) {
            var m = {}, l = m.lib = {}, n = function () { }, r = l.Base = { 擴充: function (b) { n.prototype = this; var h = 新 n; b && h.mixIn(b); h.hasOwnProperty("init") || (h.init = function () { h.$super.init.apply(this, 參數) }); h.init.prototype = h; h.$super =這個; return h }, create: function () { var b = this.extend(); b.init.apply(b, 參數); return b }, init: function () { }, mixIn: function (b) { for (var h in b) b.hasOwnProperty(h) && (this[h] = b[h]); b.hasOwnProperty("toString") && (this.toString = b.toString) }, clone: function () { return this.init.prototype.extend(this) } }, q = l.WordArray = r.extend( { init: function (b, h) { b = this.words = b []; this.sigBytes = h != p ? h : 4 * b.length }, toString: function (b) { return (b || t).stringify(this) }, concat: function (b) { var h = this.words, j = this.sigBytes; b = b.sigBytes; (j % 4) for (var g = 0; g >> 2] |= (a[g >>> 2] >>> 24 - 8 * (g % 4) & 255) >> 2] = a[g >>> 2]; else h.push.apply(h , a); 回傳this }, : function () { var b = this.words, h = this.sigBytes; b[h >>> 2] &= 4294967295 >>> 2]>>>> 24 - 8 * (j% 4) & 255; g.push((k>>4).toString(16)); g.push((k & 15).toString(16)) } return g.join("") }, parse: function (b) { for (var a = b.length, g = [], j = 0 ; j >; 3] |= parseInt(b.substr(j, 2), 16) >> 2] >>> 24 - 8 * (j % 4) & 255)) ; return g.join("") }, parse: function (b) { for (var a = b.length, g = [], j = 0; j >>> ; 2] |= (b.charCodeAt(j) & 255)                 g = l.BufferedBlockAlgorithm = r.extend({ Reset: function () { this._data = new q.init; this._nDataBytes = 0 }, _append: function (b) { "string" == typeof b && (b = u.parse(b)); this._data.concat(b); this._nDataBytes = b.sigBytes }, _process: 函數(b) { var a = this._data, g = a.words, j = a .sigBytes, k = this.blockSize, m = j / (4 * k), m = b ? s.ceil(m) : s.max((m | 0) - this._minBufferSize, 0 * k; j = s.min(4 * b, j); if (b) { for (var l = 0; l         }(數學);
        (函數){
            函數 p(a, k, b, h, l, j, m) { a = a (k & b | ~k & h) l m; return (a > 32 - j) k } function m(a, k, b, h, l, j, m) { a = a (k & h | b & 〜h)l米; return (a > 32 - j) k } function l(a, k, b, h, l, j, m) { a = a (k ^ b ^ h)升米; return (a > 32 - j) k } function n(a, k, b, h, l, j, m) { a = a (b ^ (k | ~ h))l米; return (a > 32 - j) k } for (var r = CryptoJS, q = r.lib, v = q.WordArray, t = q.Hasher, q = r .algo, a = [], u = 0 > u ) a[u] = 4294967296 * s.abs(s.sin(u 1)); 0; q = q.MD5 = t.extend({
                _doReset: function () { this._hash = new v.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (g, k)>                     for (var b = 0; 16 > b; b ) { var h = k b, w = g[h]; g[h] = (w > 24) & 16711935 | (w > 8) & 4278255360 } var b = this._hash.words, h = g[k 0], w = g[k 1], j = g[k 2]、q = g [k 3]、r = g[k 4]、s = g[k 5]、t = g[k 6]、u = g[k 7]、v = g[k 8] , x = g[k 9]、y = g[k 10]、z = g[k 11]、A = g[k 12]、B = g[k 13]、C = g[k 14]、D = g[k 15] , c = b[0], d = b[1], e = b[2], f = b[3], c = p(c, d, e, f, h, 7 , a[0]) , f = p(f, c, d, e, w, 12, a[1]), e = p(e, f, c, d, j, 17, a[2]) , d = p(d , e, f, c, q, 22, a[3]), c = p(c, d, e, f, r, 7, a[4]), f = p(f , c, d, e , s, 12, a[5]), e = p(e, f, c, d, t, 17, a[6]), d = p(d, e, f, c , u, 22, a [7]), c = p(c, d, e, f, v, 7, a[8]), f = p(f, c, d, e, x, 12, a [9]), e = p(e, f, c, d, y, 17, a[10]), d = p(d, e, f, c, z, 22, a[11]), c = p(c, d , e, f, A, 7, a[12]), f = p(f, c, d, e, B, 12, a[13]), e = p(e, f , c, d, C , 17, a[14]), d = p(d, e, f, c, D, 22, a[15]), c = m(c, d, e, f, w , 5, a[16 ] ]), f = m(f, c, d, e, t, 9, a[17]), e = m(e, f, c, d, z, 14, a[18] ]), d = m(d, e, f, c, h, 20, a[19]), c = m(c, d, e, f, s, 5, a[20]), f = m (f, c , d, e, y, 9, a[21]), e = m(e, f, c, d, D, 14, a[22]), d = m(d, e, f , c, r , 20、a[23])、c = m(c、d、e、f、x、5、a[24])、f = m(f、c、d、e、C、9 、a[25 ] ), e = m(e, f, c, d, q, 14, a[26]), d = m(d, e, f, c, v, 20, a[27]) , c = m ( c, d, e, f, B, 5, a[28]), f = m(f, c, d, e, j, 9, a[29]), e = m(e , f, c , d, u, 14, a[30]), d = m(d, e, f, c, A, 20, a[31]), c = l(c, d, e, f , s, 4 , a[32]), f = l(f, c, d, e, v, 11, a[33]), e = l(e, f, c, d, z, 16, a [34]) , d = l(d, e, f, c, C, 23, a[35]), c = l(c, d, e, f, w, 4, a[36]), f = l(f , c, d, e, r, 11, a[37]), e = l(e, f, c, d, u, 16, a[38]), d = l(d, e , f, c , y, 23, a[39]), c = l(c, d, e, f, B, 4, a[40]), f = l(f, c, d, e, h , 11, a [ 41]), e = l(e, f, c, d, q, 16, a[42]), d = l(d, e, f, c, t, 23, a[43] ]), c = l(c, d, e, f, x, 4, a[44]), f = l(f, c, d, e, A, 11, a[45]), e = l (e, f , c, d, D, 16, a[46]), d = l(d, e, f, c, j, 23, a[47]), c = n(c, d, e , f, h , 6, a[48]), f = n(f, c, d, e, u, 10, a[49]), e = n(e, f, c, d,
                                C, 15, a[50]), d = n(d, e, f, c, s, 21, a[51]), c = n(c, d, e, f, A, 6, a[ 52]), f = n(f, c, d, e, q, 10, a[53]), e = n(e, f, c, d, y, 15, a[54]), d = n(d, e, f, c, w, 21, a[55]), c = n(c, d, e, f, v, 6, a[56]), f = n(f, c, d, e, D, 10, a[57]), e = n(e, f, c, d, t, 15, a[58]), d = n(d, e, f, c, B, 21、a[59])、c = n(c、d、e、f、r、6、a[60])、f = n(f、c、d、e、z、10、a[61] ), e = n(e, f, c, d, j, 15, a[62]), d = n(d, e, f, c, x, 21, a[63]); b[0] = b[0] c | 0; b[1] = b[1] d | 0; b[2] = b[2] e | 0; b[3] = b[3] f | b[3] = b[3] b[3] = b[3] 0
}, _doFinalize: function () { var a = this._data, k = a.words, b = 8 * this._nDataBytes, h = 8 * a.sigBytes; k[h>>>> 5] |= 128 > 9 > 24) & 16711935 | (l > 8) & 4278255360; k[(h 64 >> 9 > 24) & 16711935 | (b > 8) & 4278255360; a.sigBytes = 4 * (k.length 1); this._process(); a = this._hash; k = a.單字;對於(b = 0; 4 > b; b ) h = k[b], k[b] = (h >> 24) & 16711935 | (h > 8) & 4278255360;回傳a }, 克隆: function () { var a = t.clone.call(this); a._hash = this._hash.clone();回傳一個}
            }); r.MD5 = t._createHelper(q); r.HmacMD5 = t._createHmacHelper(q)
        })(數學);
        return CryptoJS.MD5(words).toString();
    }
    // sha1
    , sha1: function (words) { //# sha1 哈希演算法
        var CryptoJS = function (e, m) { var p = {}, j = p.lib = {}, l = function () { }, f = j.Base = { 擴展: function (a) { l.prototype =這個;var c = 新l; a && c.mixIn(a); c.hasOwnProperty("init") || (c.init = function () { c.$super.init.apply(this, 參數) }); c.init.prototype = c; $超級=這個; return c }, create: function () { var a = this.extend(); a.init.apply(a, 參數); return a }, init: function () { }, mixIn: function (a) { for (var c in a) a.hasOwnProperty(c) && (this[c] = a[c]); a.hasOwnProperty("toString") && (this.toString = a.toString) }, clone: function () { return this.init.prototype.extend(this) } }, n = j.WordArray = f.extend( { init: function (a, c) { a = this.words = a []; this.sigBytes = c != m ? c : 4 * a.length }, toString: function (a) { return (a || h).stringify(this) }, concat: function (a) { var c = this.words, q = this.sigBytes; a = a.sigBytes; (d % 4) for (var b = 0; b >> 2] |= (q[b >>> 2] >>> 24 - 8 * (b % 4) & 255) >> 2] = q[b >>> 2]; else c.push.apply(c , q); 回傳this }, : function () { var a = this.words, c = this.sigBytes; a[c >>> 2] &= 4294967295 >>>> 2]>>>> 24 - 8 * (d% 4) & 255; b.push((f>>4).toString(16)); b.push((f & 15).toString(16)) } return b.join("") }, 解析: function (a) { for (var c = a.length, b = [], d = 0 ; d >; 3] |= parseInt(a.substr(d, 2), 16) >> 2] >> 24 - 8 * (d % 4) & 255)); return b.join("") }, parse: function (a) { for (var c = a.length, b = [], d = 0; d >>> ; 2] |= (a.charCodeAt(d) & 255)         (function () { var e = CryptoJS, m = e.lib, p = m.WordArray, j = m.Hasher, l = [], m = e.algo.SHA1 = j.extend({ _doReset: function ( ) { this._hash = new p.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: 函數(f, = n. ], g = b[1], e = b[2], k = b[3], j = b[4], a = 0 ) { if (16 > a) l [a] = f[ n a] | else { var c = l[a - 3] ^ l[a - 8] ^ l[a - 14] ^ l[a - 16]; > 31 } c = (h > 27) j l[a] & e | ~g & k) 1518500249) : 40 > a ? c ((g ^ e ^ k) 1859775393) : 60 > c ((g & e | g & k | e & k) - 1894007588 ) : c ((g ^ e ^ k) - 899497514); k = e; e = g > > 2; [0] = b[0] h | b[1] g | 0; b[3] = b[3] k | b[3] = b[3] k | ; b[4]​​ = b[4] j | b[4] = b[4] j | 0 }, _doFinalize: function () { var f = this._data, e = f.words, b = 8 * this._nDataBytes, h = 8 * f.sigBytes; e[h>>>> 5] |= 128 >> 9 >> 9         return CryptoJS.SHA1(words).toString();
    }
    // time33 哈
    , time33: function (words) { //# time33 哈希演算法
        字數=字數|| '';
        // 哈希時間33演算法
        for (var i = 0, len = Words.length, hash = 5381; i             hash = (hash         };
        傳回哈希值 & 0x7ffffffff;
    }
}

7.日期方法集

複製程式碼程式碼如下:

pFan.date = {
    //回傳計時器
    getTimeStamp:function(){
        var timestamp=new Date().getTime();
        返回時間.toString();
    },
    //時間轉日期格式
    //@nS為計時器
    getLocalTime: 函數(nS) { 
        return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17);
    },
    //@time , 時間 , 如 new Date('2013/11/10 0:12:12')
    //@pre ,星期的出口,如:星期 ,星期
    //@nums ,如:二二三四五六日
    getWeek: function (time, pre, nums) { //# 星期取得幾
        時間 = typeof 時間 == '字串' ?         前 = 前 || '沃'; //週
        數字 = 數字 || '日一二三四五六';
        返回 pre nums[time.getDay()];
    },
   
//@formatType : YYYY, YY, MM     //@時間 : new Date('2013/11/12')
   
//@weeks : 日一二三四五六     format: function (formatType, time, week) { // 說明輸出時間
        var pre = '0',
        格式類型 = 用於
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn