<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script>
function getCookieValue(cookieName)
{
var cookieValue = document.cookie;
var cookieStartAt = cookieValue.indexOf(" " + cookieName + "=");
if(cookieStartAt == -1)
{
cookieStartAt = cookieValue.indexOf(cookieName + "=");
}
if(cookieStartAt == -1)
{
cookieValue == null;
}
else
{
cookieSatrtAt = cookieValue.indexOf("=", cookieStartAt)+1;
cookieEndsAt = cookieValue.indexOf(";", cookieStartAt);
if(cookieEndsAt == -1)
{
cookieEndsAt == cookieValue.length;
}
cookieValue = unescape(cookieValue.substring(cookieStartAt,cookieEndsAt));
}
return cookieValue;
}
document.cookie ="name=Bob;age=20";
document.write(getCookieValue("age"));
</script>
</body>
</html>htmljavascriptcookiefunction
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script>
function getCookieValue(cookieName)
{
var cookieValue = document.cookie;
var cookieStartAt = cookieValue.indexOf(" " + cookieName + "=");
if(cookieStartAt == -1)
{
cookieStartAt = cookieValue.indexOf(cookieName + "=");
}
if(cookieStartAt == -1)
{
cookieValue == null;
}
else
{
cookieSatrtAt = cookieValue.indexOf("=", cookieStartAt)+1;
cookieEndsAt = cookieValue.indexOf(";", cookieStartAt);
if(cookieEndsAt == -1)
{
cookieEndsAt == cookieValue.length;
}
cookieValue = unescape(cookieValue.substring(cookieStartAt,cookieEndsAt));
}
return cookieValue;
}
document.cookie ="name=Bob;age=20";
document.write(getCookieValue("age"));
</script>
</body>
</html>htmljavascriptcookiefunction
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货