ホームページ >ウェブフロントエンド >jsチュートリアル >よく使用される JS コードの構成
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'); メソッドを呼び出します
2. インデックス値を使用してタブとコンテンツを切り替えます
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')) を呼び出して、アドレスバーのステータスパラメータを取得します
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. / 携帯電話のシステム Android または 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 コードの構成の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。