• JQuery Cookie


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    	String path = request.getContextPath();
    	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    	pageContext.setAttribute("path", path);
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Cookie Test</title>
        <script type="text/javascript" src="${path }/js/lhgdialog/jquery-1.7.2.min.js"></script>
        <script type="text/javascript">
    		function set(){
    			$.cookie("menu", "测试!");  //设置cookie的值
    			alert("setCookie SUCCESS!");
    		}
    		function show(){
    			var menu = $.cookie("menu");	//取cookie的值
    			
    			if(menu != null){
    				$("#d").html(menu);
    			}else{
    				$("#d").html("cookie为空!");
    			}
    		}
    		function del(){
    			 $.cookie("menu", null);  //删除cookie
    			 alert("deleteCookie SUCCESS!");
    		}
    		
    		jQuery.cookie = function(name, value, options) {
    		    if (typeof value != 'undefined') { // name and value given, set cookie
    		        options = options || {};
    		        if (value === null) {
    		            value = '';
    		            options.expires = -1;
    		        }
    		        var expires = '';
    		        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
    		            var date;
    		            if (typeof options.expires == 'number') {
    		                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
    		        }
    		        // CAUTION: Needed to parenthesize options.path and options.domain
    		        // in the following expressions, otherwise they evaluate to undefined
    		        // in the packed version for some reason...
    		        var path = options.path ? '; path=' + (options.path) : '';
    		        var domain = options.domain ? '; domain=' + (options.domain) : '';
    		        var secure = options.secure ? '; secure' : '';
    		        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    		    } else { // only name given, get cookie
    		        var cookieValue = null;
    		        if (document.cookie && document.cookie != '') {
    		            var cookies = document.cookie.split(';');
    		            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 + '=')) {
    		                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
    		                    break;
    		                }
    		            }
    		        }
    		        return cookieValue;
    		    }
    		};
        </script>
      </head>
      
      <body>
    		<a href="javascript:void();" onclick="set();">setCookie</a><br/><br/>
    		<a href="javascript:void();" onclick="show();">getCookie</a><br/>
    		show Cookie:<div id="d"></div><br/><br/><br/>
    		<a href="javascript:void();" onclick="del();">deleteCookie</a>
      </body>
    </html>


  • 相关阅读:
    docker下使用caffe的命令记录
    docker安装caffe
    Docker的安装及简单使用
    Docker 安装jupyter notebook
    3*3卷积核实例
    2D image convolution
    nump中的为随机数产生器的seed
    R410自带SAS6IR卡折腾记
    ROS多个网段做隔离
    python easy install时,使用aliyun阿里云镜像提示主机名不匹配的问题
  • 原文地址:https://www.cnblogs.com/jasontec/p/9601695.html
Copyright © 2020-2023  润新知