Collection of common js methods and common js Methods
Deep copy of arrays and objects
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);
Get address bar Parameters
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());
Modify title compatible with 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);}
Mobile Terminal response style
/* After the method is used, a style label will be added to the head label and there is. my-resize and. no-resize style, must be adapted to the screen element plus. my-resize class name ,. no-resize is used to restore the adapted elements * window. onload = window. onresize = function () {* pageResize ({* width: '000000', // The default width is 320px * height: '000000', // The default height is 504px *}) *} */(function pageResize (opt) {var ua = navigator. userAgent, wp = ua. match (/Windows Phone ([\ d.] +)/), android = ua. match (/(Android );? [\ S \/] + ([\ d.] + )? /), // Initial ratio of device width to height dw = document.doc umentElement. clientWidth, dh = document.doc umentElement. clientHeight, ds = dw/dh, // initial ratio of page width to height opt = opt ||{}, pw = opt. width | 320, ph = opt. height | 512, ps = pw/ph; // core code: Page scaling ratio var sx = dw/pw, sy = dh/ph; var css = '. no-resize {-webkit-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;} ', head = document. getElementsByTagName ('head') [0], style = document. createElement ('style'); style. type = 'text/css '; if (style. styleSheet) {style.styleSheet.css Text = css;} else {style. appendChild (document. createTextNode (css);} head. appendChild (style );})()
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!