jquery cookies and Legend state
jquery cookies and Legend state
我使用这段代码来激活取消激活字段集和jquery cookie插件的内容,除了传说的状态,它总是返回为未选择,这反过来设置字段集内的元素禁用。
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;
};
});
};
如何设置cookie来记住Legend的状态?
编辑:我很接近,我可以通过检查它的背景颜色来获得传说的"状态"…但是我不能设置cookie来记住颜色,所以它总是会恢复到原来的状态…我做错了什么?
$(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});
}
});
});
我不确定你想在哪里设置图例状态,但你可以这样做:
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;
}
});
喝了一两杯啤酒后,我终于想通了。我将click()函数与设置cookie结合起来。
$(function(){
var legend=$('.setCookies').find('.activeLegend');
legend.each(function(){
var legendId=this.id;
var fsId=$('#'+legendId).closest('fieldset').prop('id');
$(this).css('background-color', $.cookie(legendId));
if ($('#'+legendId).css('background-color')=='rgb(178, 0, 0)'){
$('#'+fsId+' :input').prop('disabled', false);
$('#'+fsId+' input:checkbox').button('enable');
$('#'+fsId+' input:radio').button('enable');
}else{
$('#'+fsId+' :input').prop('disabled', true);
$('#'+fsId+' input:checkbox').button('disable');
$('#'+fsId+' input:radio').button('disable');
};
});
legend.click(function(){
var fsId=$(this).closest('fieldset').prop('id');
var legendId=this.id;
if ($('#'+legendId).css('background-color')=='rgb(107, 0, 0)'){
$('#'+legendId).css('background-color', '#b20000');
$('#'+fsId+' :input').prop('disabled', false);
$('#'+fsId+' input:checkbox').button('enable');
$('#'+fsId+' input:radio').button('enable');
}else{
$('#'+legendId).css('background-color', '#6b0000');
$('#'+fsId+' :input').prop('disabled', true);
$('#'+fsId+' input:checkbox').button('disable');
$('#'+fsId+' input:radio').button('disable');
};
$.cookie(legendId, $(this).css('background-color'), {expires: 365});
});
});
相关文章:
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- 在$state.go之后执行$window.location.reload(true)
- 使用Angularjs$state.go导航
- 如何删除'被按压'state from复选框
- 将Json解析为State
- $state没有'导航不正确
- Angular State Dropdown Bound to Country Select
- 将$scope数据传递给$stateProvider.state解析
- $state.go没有兑现承诺
- AJAX 请求没有在我的 React 组件中设置 this.state.data
- 离子范围值未更新 在$state之间导航
- Angularjs:将对象params传递给state
- 在jQuery中,.state()如何确定一个承诺是挂起的、已解决的还是被拒绝的
- 如何通过javascript从state.xml文件中检索所有状态名称
- 如何在用户更新AngularJs中的控制器时刷新$state
- Highcharts点击事件返回“;悬停”;state而不是“state”;选择“;状态
- 正在保存CSS State Jquery Cookie
- 带有离子导航视图的Ionic中的$state.go不起作用
- 如何在redux模块中创建一个helper类型的函数,从state返回一组经过过滤的只读数据
- jquery cookies and Legend state