其他分享
首页 > 其他分享> > 总结的一些函数

总结的一些函数

作者:互联网

1.一位数组切割成二维数组

hdandle: function(lists,pageSize){
        var newLists = [];
        var temLists = [];
        if (lists.length > 0) {
            for (var i = 0, lth = lists.length; i < lth; i++) {
                lists[i].index = i;
                temLists.push(lists[i]);
                if ((i + 1) % pageSize === 0 || (i === lth - 1 && (i + 1) % pageSize !== 0)) {
                    newLists.push(temLists);
                    temLists = [];
                }
            }
        };
        return newLists;
    }

2.判断链接是否为图片

function isImg(str){
    var patt = /[.png|.jpg|.jpeg|.gif|.bmp|.webp|.ico|.svg]$/i;
     return patt.test( str.replace(/\s*/g,"") );
};

3.无线和pc的判断

function(){
   var sUserAgent = navigator.userAgent.toLowerCase();
          var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
          var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
          var bIsMidp = sUserAgent.match(/midp/i) == "midp";
          var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
          var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
          var bIsAndroid = sUserAgent.match(/android/i) == "android";
          var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
          var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
          if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
          //pc页面
          
          }else {
            //无线页面
            window.location.href="https://peixun.1688.com/cms/yysbfwx.html";
          }  
}

 

标签:总结,函数,windows,sUserAgent,lists,var,一些,match,temLists
来源: https://www.cnblogs.com/sbzf/p/11326730.html