• javascript中常见的函数封装 :判断是否是手机,判断是否是微信,获取url地址?后面的具体参数值,毫秒格式化时间,手机端px、rem尺寸转换等


    // 判断是否是手机
    function plat_is_mobile(){
      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 (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
      return true;
    } else {
      return false;
    }
    }
    // 判断是否是手机
    // 判断是否是微信
    function isWeiXin(){
      var ua = window.navigator.userAgent.toLowerCase();
      if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
      }else{
        return false;
      }
    }
    // 判断是否是微信
    // 获取url地址?后面的具体参数值
    function GetArgsFromHref(sArgName){
      var sHref =top.location.href;
      var args= sHref.split("?");
      var retval = "";
      if(args[0] == sHref) {
        return retval;
      }
      var str = args[1];
      args = str.split("&");
      for(var i = 0; i < args.length; i ++) {
        str = args[i];
        var arg = str.split("=");
        if(arg.length <= 1) continue;
        if(arg[0] == sArgName) retval = arg[1];
      }
      return retval;
    };
    // 获取url地址?后面的具体参数值
    // 毫秒格式化时间
    function getLocalTime(time){
      var datetime = new Date();
      datetime.setTime(time);
      var year = datetime.getFullYear();
      var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
      var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
      var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
      var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
      var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
      return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
    };
    // 毫秒格式化时间
    //前端手机px、rem尺寸转换js代码
    function mobile(){
      var size=100, //规定rem与px之间值的转换
      maxWidth =750; //设置基准宽度。
      ratio = function(){
        var r = document.documentElement.clientWidth / maxWidth;
        return r>=1?1:r<=0.234?0.234:r;
      };
      set = function(){
      document.documentElement.style.fontSize = ratio() * size +'px';
      }();
      window.onresize = mobile;
    }
    mobile();
    //前端手机px、rem尺寸转换js代码

  • 相关阅读:
    dwSun带你选Python的编辑器/IDE
    ubuntu中文乱码解决
    解决matplotlib中文显示
    1506.01186-Cyclical Learning Rates for Training Neural Networks
    1503.02531-Distilling the Knowledge in a Neural Network.md
    1804.03235-Large scale distributed neural network training through online distillation.md
    mysql导入太慢解决方法
    已某个时间单位(日月周年)来分割时间段
    阿里云邮件推送
    阿里云短信推送服务
  • 原文地址:https://www.cnblogs.com/kelly2017/p/7263063.html
Copyright © 2020-2023  润新知