jQuery瀹炰緥-璁颁綇鐧诲綍淇℃伅

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery瀹炰緥-璁颁綇鐧诲綍淇℃伅相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

鏈枃浠嬬粛涓媕query 璁颁綇鐧诲綍淇℃伅鐨勬柟娉曪紝寮曞叆jquery.cookie.js鏂囦欢锛屽疄鐜拌浣忕櫥褰曚俊鎭紝鏈夐渶瑕佺殑鏈嬪弸鍙傝€冧笅銆?/p>

棣栧厛锛屽鍏query.cookie.js

$(function(){
   //鍒濆鍖栭〉闈㈡椂楠岃瘉鏄惁璁颁綇浜嗗瘑鐮?/span>
    if ($.cookie("autologin") == "true") {
        $("#autologin").attr("checked", true);
        $("#account").val($.cookie("account"));
        $("#pwd").val($.cookie("pwd"));
    }
});
 
//淇濆瓨鐢ㄦ埛淇℃伅
function saveUserInfo() {
銆€銆€var  xuanzhong = document.getElementById("autologin").checked;
銆€銆€if (xuanzhong) {
銆€銆€銆€銆€var account = $("#account").val();
銆€銆€銆€銆€var pwd = $("#pwd").val();
銆€銆€銆€銆€$.cookie("autologin", "true", { expires: 7 }); // 瀛樺偍涓€涓甫7澶╂湡闄愮殑 cookie
銆€銆€銆€銆€$.cookie("account", account, { expires: 7 }); // 瀛樺偍涓€涓甫7澶╂湡闄愮殑 cookie
銆€銆€$.cookie("pwd", pwd, { expires: 7 }); // 瀛樺偍涓€涓甫7澶╂湡闄愮殑 cookie
銆€銆€}
銆€銆€else {
銆€銆€銆€銆€$.cookie("autologin", "false", { expires: -1 });
銆€銆€銆€銆€$.cookie("account", 鈥樷€? { expires: -1 });
銆€銆€銆€銆€$.cookie("pwd", 鈥樷€? { expires: -1 });
銆€銆€}
}

jquery.cookie.js

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie(鈥榯he_cookie鈥? 鈥榯he_value鈥?;
 * @desc Set the value of a cookie.
 * @example $.cookie(鈥榯he_cookie鈥? 鈥榯he_value鈥? {expires: 7, path: 鈥?鈥? domain: 鈥榡query.com鈥? secure: true});
 * @desc Create a cookie with all available options.
 * @example $.cookie(鈥榯he_cookie鈥? 鈥榯he_value鈥?;
 * @desc Create a session cookie.
 * @example $.cookie(鈥榯he_cookie鈥? null);
 * @desc Delete a cookie by passing null as value.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/[email protected]
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie(鈥榯he_cookie鈥?;
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/[email protected]
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 鈥榰ndefined鈥? { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = 鈥樷€?span style="color: #000000;">;
            options.expires = -1;
        }
        var expires = 鈥樷€?span style="color: #000000;">;
        if (options.expires && (typeof options.expires == 鈥榥umber鈥?|| options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 鈥榥umber鈥?span style="color: #000000;">) {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = 鈥? expires=鈥?+ date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? 鈥? path=鈥?+ options.path : 鈥樷€?span style="color: #000000;">;
        var domain = options.domain ? 鈥? domain=鈥?+ options.domain : 鈥樷€?span style="color: #000000;">;
        var secure = options.secure ? 鈥? secure鈥?: 鈥樷€?span style="color: #000000;">;
        document.cookie = [name, 鈥?鈥? encodeURIComponent(value), expires, path, domain, secure].join(鈥樷€?span style="color: #000000;">);
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != 鈥樷€?span style="color: #000000;">) {
            var cookies = document.cookie.split(鈥?鈥?span style="color: #000000;">);
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + 鈥?鈥?span style="color: #000000;">)) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

 

以上是关于jQuery瀹炰緥-璁颁綇鐧诲綍淇℃伅的主要内容,如果未能解决你的问题,请参考以下文章

Spring+ Spring cloud + SSO鍗曠偣鐧诲綍搴旂敤璁よ瘉

鏂伴椈鐧诲綍椤甸潰鍒朵綔

syslog瀹炰緥璇﹁Вrsyslog

java 鎵弿寰俊鍏紬鍙蜂簩缁寸爜锛屽叧娉ㄥ苟鐧诲綍閫昏緫

Echarts涓お闃冲浘锛圫unburst锛夌殑瀹炰緥

浣跨敤GFS闆嗙兢閮ㄧ讲KVM铏氭嫙鍖栧钩鍙?瀹炰緥!!!)