Cookie与jQuery [英] cookies with jQuery
本文介绍了Cookie与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下:
< input type =checkboxvalue =vat_50name =vat_50class =tax>
< input type =checkboxvalue =vat_34name =vat_50class =tax>
< input type =checkboxvalue =vat_12name =vat_50class =tax>
如何设置cookie,上面的复选框?
我看过 $。cookie
,但不知道该如何实现。
感谢
解决方案
尝试使用jquery cookie plugin
$(document).ready function(){
var name = $(this).attr(name);
var value = $(this).val();
$ .cookie(name,value,{expires:365}); //根据你的要求设置expires时间
} b $ b});
I have a list of checkboxes, that I'd like, when clicked to be added to a cookie using jQuery.
My code is like:
<input type="checkbox" value="vat_50" name="vat_50" class="tax">
<input type="checkbox" value="vat_34" name="vat_50" class="tax">
<input type="checkbox" value="vat_12" name="vat_50" class="tax">
How would I set the cookie, for the checkboxes above?
I've seen $.cookie
, but not sure how to implement it.
Thanks
解决方案
Try this provided you using jquery cookie plugin
$(document).ready( function() {
$('input:checkbox').click(function() {
var name = $(this).attr("name");
var value = $(this).val();
$.cookie(name, value, { expires: 365 });//Set the expires time as per your requirement.
});
});
这篇关于Cookie与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文