在下面的功能,有一行: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