日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 前端文檔 正文

Angular?Cookie?讀寫操作代碼_AngularJS

作者:飛翔的小倉鼠 ? 更新時間: 2022-03-23 前端文檔

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

欄目分類
最近更新