日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
前端實用小工具(URL參數(shù)截取、JSON判斷、數(shù)據(jù)類型檢測、版本號對比等)

 URL截取參數(shù)

創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網綜合服務,包含不限于網站建設、成都網站建設、虹口網絡推廣、微信平臺小程序開發(fā)、虹口網絡營銷、虹口企業(yè)策劃、虹口品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學生創(chuàng)業(yè)者提供虹口建站搭建服務,24小時服務熱線:028-86922220,官方網址:www.cdcxhl.com

 
 
 
 
  1. //直接調用輸入想要截取的參數(shù)名稱幾個 
  2. export function getParamFromUrl(key) { 
  3.     if (key === undefined) return null; 
  4.     let search = location.search.substr(1); 
  5.     let mReg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)'); 
  6.     let mValue = search.match(mReg); 
  7.     if (mValue != null) return unescape(mValue[2]); 
  8.     return null; 
  9. //示例 
  10. let city = getParamFromUrl('city'); 

JSON是否為空判斷

 
 
 
 
  1. //輸入想要檢測的json數(shù)據(jù) 如果為空返回返回false 
  2. export function isNullObject(model) { 
  3.   if (typeof model === "object") { 
  4.     let hasProp = false; 
  5.     for (const prop in model) { 
  6.         hasProp = true; 
  7.         break; 
  8.     } 
  9.     if (hasProp) { 
  10.         return false; 
  11.     } 
  12.     return true; 
  13.   } else { 
  14.       throw "model is not object"; 
  15.   } 

數(shù)據(jù)類型檢測

 
 
 
 
  1. //檢測變量的數(shù)據(jù)類型 
  2. export function getParamType(item) { 
  3.     if (item === null) return null; 
  4.     if (item === undefined) return undefined; 
  5.     return Object.prototype.toString.call(item).slice(8, -1); 
  6. //返回String Function Boolean Object Number 

獲取cookie

 
 
 
 
  1. //獲取document下cookie的具體某個參數(shù)值 
  2. export function getCookie(key) { 
  3.     if (key === undefined) { 
  4.         return undefined; 
  5.     } 
  6.     let cookies = document.cookie; 
  7.     let mReg = new RegExp('(^|;)\\s*' + key + '=([^;]*)(;|$)'); 
  8.     let mValue = cookies.match(mReg); 
  9.     let ret = undefined; 
  10.     if (mValue != null) { 
  11.         ret = unescape(mValue[2]); 
  12.     } 
  13.     if (ret !== undefined) { 
  14.         ret = ret.replace(/^\"|\'/i, '').replace(/\"|\'$/i, ''); 
  15.     } 
  16.     return ret; 

版本號對比
一般在做APP端開發(fā)的時候需要用到一些版本控制,那么就需要針對版本號來進行對比,高版本或者低版本做一些特殊的邏輯處理,下面就是提供版本對比的方法

 
 
 
 
  1. //傳入要對比的版本號,一般前面一個傳入當前的版本號,后面一個寫上要對比的版本號 
  2. export function versionCompare(higher, lower) { 
  3.     let sep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.'; 
  4.  
  5.     let higherAry = higher.split(sep), 
  6.         lowerAry = lower.split(sep); 
  7.     let l = Math.max(higherAry.length, lowerAry.length); 
  8.     for (let i = 0; i < l; i++) { 
  9.         let high = parseInt(higherAry[i] || 0); 
  10.         let low = parseInt(lowerAry[i] || 0); 
  11.         if (high > low) { 
  12.             return 1; 
  13.         } 
  14.         if (high < low) { 
  15.             return -1; 
  16.         } 
  17.     } 
  18.     return 0; 
  19. //返回值  higher > lower: 1;higher = lower: 0;higher < lower:-1 

數(shù)組去重

 
 
 
 
  1. export function arrayUniq(array){ 
  2.     let temp = [];  
  3.     for(var i = 0; i < array.length; i++){ 
  4.         if(temp.indexOf(array[i]) == -1){ 
  5.             temp.push(array[i]); 
  6.         } 
  7.     } 
  8.     return temp; 

iPhone X系列機型判斷

 
 
 
 
  1. export function isIphoneX() { 
  2.     // iPhone X、iPhone XS 
  3.     var isIPhoneX = 
  4.         /iphone/gi.test(window.navigator.userAgent) && 
  5.         window.devicePixelRatio && 
  6.         window.devicePixelRatio === 3 && 
  7.         window.screen.width === 375 && 
  8.         window.screen.height === 812; 
  9.     // iPhone XS Max 
  10.     var isIPhoneXSMax = 
  11.         /iphone/gi.test(window.navigator.userAgent) && 
  12.         window.devicePixelRatio && 
  13.         window.devicePixelRatio === 3 && 
  14.         window.screen.width === 414 && 
  15.         window.screen.height === 896; 
  16.     // iPhone XR 
  17.     var isIPhoneXR = 
  18.         /iphone/gi.test(window.navigator.userAgent) && 
  19.         window.devicePixelRatio && 
  20.         window.devicePixelRatio === 2 && 
  21.         window.screen.width === 414 && 
  22.         window.screen.height === 896; 
  23.     if (isIPhoneX || isIPhoneXSMax || isIPhoneXR) { 
  24.         return true; 
  25.     } 
  26.     return false; 

新聞名稱:前端實用小工具(URL參數(shù)截取、JSON判斷、數(shù)據(jù)類型檢測、版本號對比等)
分享網址:http://www.5511xx.com/article/cdhsdse.html