dsegw3424 2013-06-20 11:59
浏览 70
已采纳

在jquery中设置cookie变量

I am trying to set a cookie in jquery using :

 $( "a.Edit" ) .click(function() { 
$( "#dialog-form" ).dialog( "open" );
 var un=$(this ).text();
 $.cookie("test", un);
  });

but when i use it after that <?php echo $_COOKIE['test'] ?> it wont work the cookie is still not set

any help please

thanks in advance

  • 写回答

3条回答 默认 最新

  • dongtang1910 2013-06-20 12:06
    关注

    Use the jquery_cookie() plugin for this.

    $.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
    

    Where the_cookie is the name of your cookie. and where the_value of your cookie is the value/function it has to do. expires 7 means that the cookie wil expire in 7 days (one week) Path isn't nessesary,

    Define the path where the cookie is valid. By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior). If you want to make it available for instance across the entire domain use path: '/'. Default: path of page where the cookie was created.

    You can remove the cookie using:

    $.removeCookie('the_cookie');
    

    you can read the cookie using:

    $.cookie('the_cookie');
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面