È possibile modificare TUTTO il codice in solo: MODIFICA per rimuovere la parte non necessaria.
$(document).ready(function(){
// read the current/previous setting
$("input.box[type=checkbox]").each(function() {
var name = $(this).attr('name');
if ($.cookie(name) && $.cookie(name) == "true") {
$(this).prop('checked', $.cookie(name));
}
});
// event management
$("input.box[type=checkbox]").change(function() {
var name = $(this).attr("name");
$.cookie(name, $(this).prop('checked'), {
path: '/',
expires: 365
});
});
});
tra cui sbarazzarsi di tutto questo:
$(document).ready(function(){
remember("[name=1]");
});
...
EDIT: versione meno prolissa:
$("input.box").each(function() {
var mycookie = $.cookie($(this).attr('name'));
if (mycookie && mycookie == "true") {
$(this).prop('checked', mycookie);
}
});
$("input.box").change(function() {
$.cookie($(this).attr("name"), $(this).prop('checked'), {
path: '/',
expires: 365
});
});
esempio funzionante: http://jsfiddle.net/R73vy/
fonte
2012-12-18 16:51:47
Questo link a Dropbox fornisce un 404. Qualcosa come un JSFiddle sarebbe stato utile per coloro che verranno dopo. – Ojen