国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

常用的js方法合集

2024-05-06 16:35:42
字體:
供稿:網(wǎng)友

數(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í)或者工作能帶來一定的幫助,同時也希望多多支持VeVb武林網(wǎng)!


注:相關(guān)教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥宁县| 乌鲁木齐市| 景东| 洛隆县| 循化| 延川县| 曲水县| 靖江市| 马公市| 延寿县| 新野县| 西峡县| 玉环县| 资源县| 岑溪市| 虹口区| 正定县| 内丘县| 仁布县| 彭泽县| 岐山县| 尖扎县| 陆丰市| 饶阳县| 全椒县| 玉山县| 砚山县| 同心县| 二连浩特市| 定边县| 陵川县| 乡宁县| 得荣县| 华宁县| 若尔盖县| 兖州市| 桂林市| 高碑店市| 丽水市| 绥滨县| 泰宁县|