javascript - jquery cookies and Legend state -
i'm using code activate disactivate contents of fieldsets , jquery cookies plugin works except state of legend comes unselected in turn sets elements inside fieldset disabled.
function activelegend(){ var legendid=this.id var fsid=$(this).closest('fieldset').prop('id') var inputs=$('#'+fsid).find(':input') inputs.each(function(){ if ($(this).is(':disabled')){ $('#'+legendid).css('background-color', '#6b0000'); $('#'+fsid+' :input').prop('disabled', false); $('#'+fsid+' input:checkbox').button('enable'); $('#'+fsid+' input:radio').button('enable'); return false; }else{ $('#'+legendid).css('background-color', '#b20000'); $('#'+fsid+' :input').prop('disabled', true); $('#'+fsid+' input:checkbox').button('disable'); $('#'+fsid+' input:radio').button('disable'); return false; }; }); };
how can set cookie remember state of legend?
edit:
i'm close, i'm able legend 'state' checking it's background color... can't set cookie remember color reverts it's original state... doing wrong?
$(function(){ var legend=$('.setcookies').find('.activelegend'); legend.each(function(){ $(this).css('background-color', $.cookie(this.id)); }); legend.click(function(){ var fsid=$(this).closest('fieldset').prop('id') var legendid=this.id if ($('#'+legendid).css('background-color')=='rgb(178, 0, 0)'){ $('#'+legendid).css('background-color', '#6b0000'); $('#'+fsid+' :input').prop('disabled', true); $('#'+fsid+' input:checkbox').button('disable'); $('#'+fsid+' input:radio').button('disable'); $.removecookie(this.id); }else{ $('#'+legendid).css('background-color', '#b20000'); $('#'+fsid+' :input').prop('disabled', false); $('#'+fsid+' input:checkbox').button('enable'); $('#'+fsid+' input:radio').button('enable'); $.cookie(this.id, {expires: 365}); } }); });
i'm not sure want set legend state, can this:
inputs.each(function(){ var element = $(this); var id = element .attr('id'); $.cookie(id, element.text()); if ($(this).is(':disabled')){ $('#'+legendid).css('background-color', '#6b0000'); $('#'+fsid+' :input').prop('disabled', false); $('#'+fsid+' input:checkbox').button('enable'); $('#'+fsid+' input:radio').button('enable'); return false; }else{ $('#'+legendid).css('background-color', '#b20000'); $('#'+fsid+' :input').prop('disabled', true); $('#'+fsid+' input:checkbox').button('disable'); $('#'+fsid+' input:radio').button('disable'); return false; } });
Comments
Post a Comment