[英]How do I insert a cookie data value into a hidden form field?
I would like to be able to take data stored in a cookie and insert it into a hidden form value. 我希望能够获取存储在cookie中的数据并将其插入到隐藏的表单值中。
I am storing the data in a cookie using the following: 我使用以下方法将数据存储在cookie中:
<script type="text/javascript">
$(function () {
$("#btnCookie").bind("click", function () {
$.cookie("name", $("#txtName").val());
I am able to retrieve the value as plain text on the next page using: 我可以使用下一页在纯文本上检索值:
$.cookie("name")
I have a form on the 2nd page that I want this value to be a part of. 我在第二页上有一个表单,希望该值成为其中的一部分。 How can I insert it into the following:
如何将其插入以下内容:
<input type="hidden" name="cookie" />
I have tried this but it doesn't work: 我已经尝试过了,但是没有用:
<input type="hidden" name="cookie" value="$.cookie("name")" />
You can do it like this, 你可以这样
var cookie_val = $.cookie("name");
$('input[name=cookie]').val(cookie_val);
<input type="hidden" name="cookie" value="$.cookie('name')" />
双引号导致HTML中的错误。
Try this jquery cookie u can use in php. 试试这个可以在php中使用的jquery cookie。
value="<?php echo $_COOKIE['name']; ?>"
or use jquery
$('input[name=cookie]').val($.cookie("name"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.