最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

常用的js方法合集

 更新時間:2017年03月10日 11:47:59   作者:fe_kevin  
本文主要介紹了常用的js方法的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧

數(shù)組及對象深拷貝

var arr = [1,'2',{a:1,b:[1,2]}];
function deepCopy(p, c) {    
 var c = c || {};    
 for (var i in p) {      
 if (typeof p[i] === 'object' && p[i] !== null) {  c[i] = (p[i].constructor === Array) ? [] : {};    deepCopy(p[i], c[i]);      
 } else {         
  c[i] = p[i];      
 }    
 }    
 return c;  
}
var cArr = deepCopy(arr);
console.log(cArr);

獲取地址欄參數(shù)

function getUrlParam(){
 var _arr = location.search.substr(1).split('&');
 var _obj = {};
 for (var i = 0; i < _arr.length; i++) {
 _obj[_arr[i].split('=')[0]] = _arr[i].split('=')[1]
 };
 return _obj;
}
console.log(getUrlParam());

修改微信title 兼容ios

function changeWxTitle(text){
 var $body = $('body');
 document.title = text;
 var $iframe = $('<iframe src="/favicon.ico"></iframe>');
 $iframe.on('load',function() {
 setTimeout(function() {
  $iframe.off('load').remove();
 }, 0);
 }).appendTo($body);
}

移動端響應(yīng)式樣式

/* 方法使用后會在 head標(biāo)簽添加一個style標(biāo)簽 并且有.my-resize 和 .no-resize的樣式,需要適配屏幕的元素加上.my-resize類名即可,.no-resize是還原已適配的元素
 * window.onload = window.onresize = function(){
 *   pageResize({
 *     width : '320',   //默認(rèn)寬320px 
 *     height : '504',   //默認(rèn)高504px
 *   })
 *  }
 */
(function pageResize(opt) {
  var ua = navigator.userAgent,
    wp = ua.match(/Windows Phone ([\d.]+)/),
    android = ua.match(/(Android);?[\s\/]+([\d.]+)?/),
    // 設(shè)備寬高初始比例
    dw = document.documentElement.clientWidth,
    dh = document.documentElement.clientHeight,
    ds = dw / dh,
    // 頁面寬高初始比例
    opt = opt || {},
    pw = opt.width || 320,
    ph = opt.height || 512,
    ps = pw / ph;
    // 核心代碼:頁面縮放比例
    var sx = dw/pw,
      sy = dh/ph; 
    var css = '.no-resize { -webkit-transform: scaleY('+sx/sy+');transform: scaleY('+sx/sy+'); }.my-resize { width:'+pw+'px !important;height:'+ph+'px !important;-webkit-transform: scale('+sx+','+sy+');transform: scale('+sx+','+sy+'); -webkit-transform-origin:left top;transform-origin:left top;}',
    head = document.getElementsByTagName('head')[0],
    style = document.createElement('style');
    style.type = 'text/css';
    if(style.styleSheet){
      style.styleSheet.cssText = css;
    }else{
      style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style); 
})()

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論

凤翔县| 新干县| 富锦市| 富蕴县| 庆云县| 伊春市| 涿州市| 墨竹工卡县| 彰化市| 勃利县| 隆回县| 克东县| 广东省| 武乡县| 吉林市| 广南县| 营山县| 马边| 兴安盟| 东平县| 偃师市| 舞钢市| 玛曲县| 沧州市| 大荔县| 武定县| 岳池县| 桐柏县| 新巴尔虎右旗| 莎车县| 砀山县| 信阳市| 北安市| 无锡市| 通榆县| 兰坪| 苗栗市| 凤冈县| 营口市| 合江县| 衡水市|