---
title: "js获取指定name的cookie"
author: "guwq2014"
date: "2019-06-20T19:38:40Z"
tags: []
categories: ["Web前端"]
slug: "js-name-cookie"
draft: false
lastmod: "2019-06-20T19:39:05Z"
id: 2442020
url: "https://guwq2014.iteye.com/blog/2442020"
---

```
function getCookie(c_name) {
		if(document.cookie.length > 0) {
			var cookieArr = document.cookie.split(';');
			for(var i=0; i<cookieArr.length; i++) {
				var arr = cookieArr[i].split('=');
				if(arr!=null && arr.length==2) {
					if(arr[0]==c_name) {
						var value = decodeURI(arr[1]);
						return value;
					}
				}
			}
		}
		return null;
	}
```