我想在一個輸入欄中存儲一個cookie,在Chrome上工作得很好,但它不能在IE-11上工作。任何人都可以告訴我我錯過了什麼,所以這個cookie也可以在IE上運行?這是我的代碼。先謝謝了。存儲在IE不工作的cookie
的Javascript:
function setCookie(key, value) {
var expires = new Date();
expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
function getCookie(key) {
var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
return keyValue ? keyValue[2] : null;
}
function myfunction() {
setCookie("input1", '1');
alert(getCookie("input1"));
document.homeForm.input1.value = getCookie("input1");
}
HTML
<form name="myform">
<input type=text name=input1 value=""/>
</form>
您的形式被稱爲'myform'但你的代碼是指'document.homeForm ...' - 是你的代碼或只是這個職位的類型? – Emissary
@Emissary只是這個職位 – progx
這段代碼對我來說工作得很好。你有cookies嗎? – gmfm