2017-11-26 11 views
0

クッキーの出力を正しく取得できないようです。私はクッキーとしてプレーヤーの名前を入力し、それを<p id="playerName"></p>の中にプリントアウトしたいと思っています。私はこれが最良の選択肢ではないことを知っていますが、私がatmのために行っていることです。事前にJavaScriptのクッキーの出力

HTML

<form name="myform" action=""> 
    Enter name: <input type="text" name="customer" /> 
    <input type="button" value="Set Cookie" onclick="WriteCookie();" /> 
    <p id="playerName"></p> 
</form> 

はJavaScript

function WriteCookie() { 
    if (document.myform.customer.value == "") { 
    alert("Du må taste inn et navn!"); 
    return; 
    } 
    cookievalue = escape(document.myform.customer.value) + ";"; 
    document.cookie = "name=" + cookievalue; 
    document.getElementById("playerName").innerHTML = cookievalue("playerName"); 
} 

感謝:)

+0

ブラウザのコンソールにスローされたエラーは良いヒントになるはずです。 – charlietfl

+0

1. cookievalue( "playerName")は関数ではありません 2. escape()関数はJavaScriptバージョン1.5では廃止されました。 – Firemen26

答えて

0
document.getElementById("playerName").innerHTML = cookievalue("playerName"); 

使用のinnerHTMLタグで何かを設定します。

+0

Iveはそれを試みましたが、それを修正することはできません。 – Haugens