我有一个用于在输入字段中设置 cookie 的 cookie 功能,以及一个保存它的按钮。当我保存并刷新页面时,输入字段再次为空。
注意:我有一个 jquery 对话框和一个粘性导航栏。也许它以某种方式覆盖了其他 jquery 代码。
我设置 cookie 的 jquery 代码:
//set cookie voor de postcode
$(function() {
$('#go').click(function(){
$.cookie('postcode', $('#postcode').val());
});
//retrieve the cookie on load if it's not undefined
if(typeof $.cookie('postcode') !== 'undefined'){
$('#postcode').val($.cookie('postcode'));
}
});
我在输入中设置 cookie 的函数。
<div id="searchbox">
<div id="search">
<fieldset>
<legend><h2>Zoeken in uw regio:</h2></legend>
<form action="<?= base_url('home/zoekresultaten') ?>">
<p class="field"><label class="field" for="Naam">Geef een zoekterm op:</label><input type="search" value="" name="postocde" /></p>
<br />
<p class="field"><label class="field" for="Naam">Kies hier een categorie:</label><select>
<option value="0" disabled selected>Alle Categorieën... </option>
<option value="1">Categorie1</option>
<option value="2">Categorie2</option>
<option value="3">Categorie3</option>
</select>
</p>
//my code to set the cookie
<p class="field"><label class="field" for="Naam">Vul hier uw postcode in:</label><input type="text" id="go" value="" name="search"/></p>
// end of the ocde
<br />
<p class="field"><label class="field" for="naam">Kies een afstand:</label><select>
<option value="0" disabled selected>Afstand...</option>
<option value="1">5km</option>
<option value="2">10km</option>
<option value="3">15km</option>
<option value="4">20km</option>
<option value="5">25km</option>
</select>
</p>
<br />
<input type="submit" id="go" class="searchbutton" value="Zoek" />
</form>
</fieldset>
</div>
我不知道为什么它不起作用。用于隐藏对话框的 cookie 工作正常,因此 cookie.js 文件加载良好。
谢谢。