总结的一些函数

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";
          }  
}

 

上一篇:js判断手机端还是电脑PC端(以及注意事项)


下一篇:判断设备,跳转到移动端和PC端