網站首頁 前端文檔 正文
Angular Cookie 讀寫操作,代碼如下所示:
var app = angular.module('Mywind',['ui.router']) app.controller('Myautumn',function($scope,$http,$filter){ //angular Cookie寫 //用法 :$scioe.addCookie("姓名",值,時間,"/") $scope.addCookie = function(name, value, days, path) { var name = decodeURI(name); var value = decodeURI(value); var expires = new Date(); expires.setTime(expires.getTime() + days * 3600000 * 24); path = path == "" ? "" : ";path=" + path; var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString(); document.cookie = name + "=" + value + _expires + path; } //angular Cookie讀 //用法:$scope.getCookieValue("姓名") $scope.getCookieValue = function(name) { var name = decodeURI(name); var allcookies = document.cookie; name += "="; var pos = allcookies.indexOf(name); if(pos != -1) { var start = pos + name.length; var end = allcookies.indexOf(";", start); if(end == -1) end = allcookies.length; var value = allcookies.substring(start, end); return(value); } else { return ""; } }; })
原文鏈接:https://www.cnblogs.com/wr1994/p/8337835.html
相關推薦
- 2022-12-08 python?datetime?和時間戳互相轉換問題_python
- 2022-06-12 Android?Flutter利用貝塞爾曲線畫一個小海豚_Android
- 2022-08-23 C++?primer超詳細講解泛型算法_C 語言
- 2022-09-07 在VScode中配置ROS環境的詳細過程_相關技巧
- 2022-01-18 獲取當前的日期 格式為YYYY-MM-dd 和時間戳轉時間
- 2022-02-27 Web server failed to start. Port XXXX was already
- 2022-07-06 python函數運行內存時間等性能檢測工具_python
- 2022-06-28 Python實現單鏈表中元素的反轉_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支