zoukankan      html  css  js  c++  java
  • JQuery $.cookie 应用

     1 if($.cookie('username')){
     2       alert('cookie exists');
     3       str = $.cookie('username');
     4       strs = str.split('&');
     5       $("input[name='username']").val(strs[0]);
     6       $("input[name='password']").val(strs[1]);
     7 }
     8 
     9  if($("#rememberme").is(":checked")){
    10         $.cookie('username',$("input[name='username']").val() + "&" + $("input[name='password']").val(),{path:"/",expires:7});
    11 }else{
    12         $.cookie('username', null, { path: '/',expires: -1 });
    13 }

     以上例子是用$.cookie来本地cookie,很久以前的插件了,慢慢学习中,跟大家分享一下

    参数设置:
    expires: (Number | Date)     

    有效期,可以设置一个整数作为有效期(单位:天),也可以设置一个日期对象作为Cookie的过期日期。如果指定日期为负数,那么此cookie将被删除;如果不设置或者设置为null,那么此cookie将被当作Session Cookie处理,并且在浏览器关闭后删除

    path:  (String)          Cookie的路径属性,默认是创建该cookie的页面路径

    domain: (String)     Cookie的域名属性,默认是创建该cookie的页面域名

    secure: (Boolean)  如果设为true,那么此cookie的传输会要求一个安全协议,例如HTTPS

    //参数为引用,懒得写。例子自己手写。

  • 相关阅读:
    sprintf使用
    Android ListView保持选中项高亮
    Creational Patterns创建型模式
    C和指针终于看到指针这一章
    C++随笔001
    TCP reset
    开始看设计模式英文版了
    Excel条件求和
    linux中安装软件,查看、卸载已安装软件方法
    linux vi文本编辑器三种模式切换及常用操作
  • 原文地址:https://www.cnblogs.com/zafuacm/p/4148440.html
Copyright © 2011-2022 走看看