这篇文章将为大家详细讲解有关常用的js方法有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。数组及对象深拷贝var arr = [1,
这篇文章将为大家详细讲解有关常用的js方法有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
数组及对象深拷贝
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);
获取地址栏参数
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);
}
移动端响应式样式
(function pageResize(opt) {
var ua = navigator.userAgent,
wp = ua.match(/windows Phone ([\d.]+)/),
Android = ua.match(/(Android);?[\s\/]+([\d.]+)?/),
// 设备宽高初始比例
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);
})()
关于“常用的js方法有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
--结束END--
本文标题: 常用的js方法有哪些
本文链接: https://www.lsjlt.com/news/78851.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0