为什么我的cookie不显示在输入字段中设置? [英] Why doesn't my cookie show in input field when set?

查看:148
本文介绍了为什么我的cookie不显示在输入字段中设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cookie函数用于在输入字段中设置cookie,还有一个按钮可以保存它。当我保存它并刷新页面输入字段是空的。



注意:我有一个jquery对话框和一个粘性导航栏。



我的jquery代码设置cookie:

  // set cookie voor de postcode 
$(function(){
$('#go')。click(function(){
$ .cookie如果没有定义,则检索负载上的cookie
如果(typeof $),$('#postcode'),$('#postcode')。val());
} .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 =fieldfor =Naam> Geef een zoekterm op:< / label>< input type =searchvalue = name =postocde/>< / p>
< br />
< p class =field>< label class =fieldfor =Naam> Kies hier een category:< / label>< select&
< option value =0disabled selected> AlleCategorieën...< / option>
< option value =1> Categorie1< / option>
< option value =2> Categorie2< / option>
< option value =3> Categorie3< / option>
< / select>
< / p>

//我的代码设置cookie

< p class =field>< label class =fieldfor =Naam> Vul hier uw postcode in:< / label>< input type =textid =govalue =name =search/>< / p&

// ocde的结尾

< br />
< p class =field>< label class =fieldfor =naam> Kies een afstand:< / label>< select&
< option value =0disabled selected> Afstand ...< / option>
< option value =1> 5公里< / option>
< option value =2> 10公里< / option>
< option value =3> 15公里< / option>
< option value =4> 20公里< / option>
< option value =5> 25公里< / option>
< / select>
< / p>
< br />
< input type =submitid =goclass =searchbuttonvalue =Zoek/>
< / form>
< / fieldset>
< / div>

我不知道为什么它不工作。
隐藏对话框的cookie工作正常,所以cookie.js文件加载得很好。



谢谢。


I have a cookie function for setting a cookie in an input field, and a button to save it. when i save it and refresh the page the input field is empty again.

NOTE: i have a jquery dialog and a sticky navigation bar. maybe it overrides the other jquery code somehow.

My jquery code to set the cookie:

//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'));
    }
});

my function to set the cookie in the input.

    <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>

I don't know why it isn't working. the cookie for hiding the dialog is working fine so the cookie.js file is loaded well.

Thanks.

解决方案

It is important to note that after setting the cookie you have to reload the page for working of the cookie. Set Cookie and destroy cookie only work after you reload the page at least once after setting and destroying cookie.

这篇关于为什么我的cookie不显示在输入字段中设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆