I can pass the checked value just fine. But when I uncheck it, the value is null and doesn't overwrite the cookie. What do you recommend?
$("input[name=box]").change(function(e) {
$.cookie("autoplay", $(e.target).val());
window.location.reload();
});
and the html
<inpu开发者_开发百科t type="checkbox" name="box" value="1">
SOLUTION:
$.cookie("autoplay", this.checked);
I just used this to track true or false.
Use the ternary operator to catch all falsy values :
$(e.target).val() ? 1 : 0
this.checked
is fastest if the value isn't necessary. As referenced here.
精彩评论