在下面的功能,有一行:JavaScript函数中这个字符串参数的用途是什么?
var username=getCookie("username");
这里的整体功能:
function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");
if (username!=null && username!="")
{
setCookie("username",username,365);
}
}
什么是“用户名”的说法点上方传递?
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
的whole code is here 谢谢!
不只是一个参数?获取名称为“用户名”的cookie。 – xdazz 2012-03-27 05:22:55
嗯,是的 - 但我们应该输入我们喜欢的任何东西(不是“用户名”),就像我们可以输入“bob”一样,例如 – Coffee 2012-03-27 05:26:28