일반적으로 사용되는 js 코드 구성

一个新手
풀어 주다: 2017-09-09 15:14:02
원래의
2225명이 탐색했습니다.

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'); 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')) 메소드를 호출하세요

3.js 타임스탬프 처리

// 传入时间戳。输出格式为:2017-05-14 00:08:46
common.pattern = function(data) {
    function replace(m) {
        return m < 10 ? &#39;0&#39; + 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()) + &#39;:&#39; + 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!