日期:2014-05-16  浏览次数:20367 次

请问一个有关cookie读取的问题
我在asp中这个写道:
Response.Cookies( "cookie1 ")( "mm3 ")=   "nickname "

那么怎么要javascript中读( "cookie1 ")( "mm3 ")这个cookie值?


在此请教了,忘各位知之士告之。

------解决方案--------------------
<script language= "javascript ">
var strCookie=unescape(document.cookie);
var strTT= "cookie1=mm3= ";
if(strCookie.indexOf(strTT)> =0)
{
var strT1=strCookie.substring(strCookie.indexOf(strTT) + strTT.length)
var strT2=strT1.substring(0,strT1.indexOf( "; "))
alert(strT2);
}

</script>
------解决方案--------------------
var strCookie=new String();
strCookie=unescape(document.cookie);
strTT= "cookie1= "
if(strCookie.indexOf(strTT)> =0)
{

var strT1=new String();
var strS=new String();
var arrStr=new Array()
strT1=strCookie.substring(strCookie.indexOf(strTT) + strTT.length)
arrStr=strT1.split( "& ");
for(var i=0;i <arrStr.length;i++)
{
strS=arrStr[i];
switch(strS.substring(0,strS.indexOf( "= ")))
{
case "mm1 ": alert( "用户名是=== " + strS.substring(strS.indexOf( "= ")));break
case "mm2 ": alert( "昵称是=== " + strS.substring(strS.indexOf( "= ")));break
case "mm3 ": alert( "笔名是=== " + strS.substring(strS.indexOf( "= ")));break
}
}
}