设为首页收藏本站

安徽论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 10244|回复: 0

Angular Cookie 读写操作代码

[复制链接]

76

主题

0

回帖

240

积分

中级会员

Rank: 3Rank: 3

积分
240
发表于 2022-3-26 11:00:38 | 显示全部楼层 |阅读模式
网站内容均来自网络,本站只提供信息平台,如有侵权请联系删除,谢谢!
Angular Cookie 读写操作,代码如下所示:
  1. var app = angular.module('Mywind',['ui.router'])
  2. app.controller('Myautumn',function($scope,$http,$filter){
  3. //angular Cookie写
  4. //用法 :$scioe.addCookie("姓名",值,时间,"/")
  5. $scope.addCookie = function(name, value, days, path) {
  6.   var name = decodeURI(name);
  7.   var value = decodeURI(value);
  8.   var expires = new Date();
  9.   expires.setTime(expires.getTime() + days * 3600000 * 24);
  10.   path = path == "" ? "" : ";path=" + path;
  11.   var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
  12.   document.cookie = name + "=" + value + _expires + path;
  13. }
  14. //angular Cookie读
  15. //用法:$scope.getCookieValue("姓名")
  16.   $scope.getCookieValue = function(name) {
  17.     var name = decodeURI(name);
  18.     var allcookies = document.cookie;
  19.     name += "=";
  20.     var pos = allcookies.indexOf(name);
  21.     if(pos != -1) {
  22.       var start = pos + name.length;
  23.       var end = allcookies.indexOf(";", start);
  24.     if(end == -1) end = allcookies.length;
  25.       var value = allcookies.substring(start, end);
  26.       return(value);
  27.     } else {
  28.       return "";
  29.     }
  30.   };
  31. })
复制代码
到此这篇关于Angular Cookie 读写操作代码的文章就介绍到这了,更多相关Angular Cookie 读写内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
                                                        
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
免责声明
1. 本论坛所提供的信息均来自网络,本网站只提供平台服务,所有账号发表的言论与本网站无关。
2. 其他单位或个人在使用、转载或引用本文时,必须事先获得该帖子作者和本人的同意。
3. 本帖部分内容转载自其他媒体,但并不代表本人赞同其观点和对其真实性负责。
4. 如有侵权,请立即联系,本网站将及时删除相关内容。
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表