1、获取地址栏参数
function request(paras) {
var url = location.search;
var parastring = url.substring(url.indexof("?") + 1, url.length).split("&");
var paraobj = {}
for (i = 0; j = parastring[i]; i++) {
paraobj[j.substring(0, j.indexof("=")).tolowercase()] = j.substring(j.indexof("=") + 1, j.length);
};
var returnvalue = paraobj[paras.tolowercase()];
if (typeof(returnvalue) == "undefined") {
return "";
} else {
return returnvalue;
};
};
调用方法, var status = request('status'); 获取地址栏中status的参数
2、jq,用索引值制作选项卡和内容之间的切换
function switch_tab(title, content) {
title.first().addclass("on");
content.first().show();
title.click(function() {
var a = $(this).index()
if(content.eq(a).css("display") != "block") {
content.hide(),
content.eq(a).show(),
title.removeclass("on"),
$(this).addclass("on");
};
});
};
调用方法,switch_tab($('.title_box .title'),$('.content_box .box'))获取地址栏中status的参数
3、js时间戳处理
// 传入时间戳。输出格式为:2017-05-14 00:08:46
common.pattern = function(data) {
function replace(m) {
return m < 10 ? '0' + m: m
}
var _date = new date(parseint(data));
var re_date = replace(_date.getfullyear()) + "-" + replace(_date.getmonth() + 1) + "-" + replace(_date.getdate()) + " " + replace(_date.gethours()) + ":" + replace(_date.getminutes()) + ':' + replace(_date.getseconds());
return re_date;
};
4、// 判断手机系统 安卓或ios
var ua = navigator.useragent.tolowercase();
if (/iphone|ipad|ipod/.test(ua)) {
} else if (/android/.test(ua)) {
};
5、阻止右键弹出查看代码
// 阻止右键
document.body.onselectstart = document.body.oncontextmenu = function() {
return false;
}
以上就是常用的js代码整理的详细内容。