Collection of common js methods and common js Methods

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.