jQuery重置复选框值

jQuery重置复选框值,jquery,Jquery,我有一个很大的jQuery函数,它在页面中创建复选框,并在选中复选框时为每个复选框指定不同的颜色 function initializeCheckboxes() { //This changes visual state of checkboxes when you click them, and binds the event to optionsCheckboxClicked function var color_codes=[]; color_codes['green']='#

我有一个很大的jQuery函数,它在页面中创建复选框,并在选中复选框时为每个复选框指定不同的颜色

function initializeCheckboxes() {
  //This changes visual state of checkboxes when you click them, and binds the event to optionsCheckboxClicked function
  var color_codes=[];
  color_codes['green']='#79A13E';
  color_codes['bordeaux']='#A74A5B';
  color_codes['red']='#CC0000';
  color_codes['orange']='#FF6600';
  color_codes['violet']='#660066';
  color_codes['pink']='#FA218C';
  jQuery('div.form_box input.checkbox').parent().unbind('click');
  jQuery('div.form_box input.checkbox').parent().click(function (){
    aCheckboxButton=this;
    if (jQuery(aCheckboxButton).attr('checked')) {
      jQuery(aCheckboxButton).removeAttr('checked');
      jQuery(aCheckboxButton).attr('class','span_checkbox');
      jQuery(aCheckboxButton).find('input').removeAttr('checked');
      jQuery(aCheckboxButton).parent().find('label').removeClass('label_checked');
      jQuery('div.form_box span.span_checkbox.disabled').attr('class','span_checkbox');
      jQuery('div.form_box label.input_text.disabled').attr('class','input_text');
      }
    else {
      total_checked=jQuery(aCheckboxButton).parent().parent().parent().find('label.input_text.label_checked').length;
      if (total_checked<6)
        {
        if (total_checked==5) {
          jQuery.each(jQuery('div.form_box input.checkbox'), function(i,v) {
            if(jQuery(v).attr('checked')) return;
            jQuery(v).parent().parent().find('span').attr('class','span_checkbox disabled');
            jQuery(v).parent().parent().find('label.input_text').attr('class','input_text disabled');
            });
          }
        jQuery(aCheckboxButton).find('input').attr('checked',true);
        jQuery(aCheckboxButton).parent().find('label.input_text').attr('class','input_text label_checked');
        colors=['span_checkbox_green','span_checkbox_bordeaux','span_checkbox_red','span_checkbox_orange','span_checkbox_violet','span_checkbox_pink'];
        jQuery.each(colors, function(i,v){
          if (jQuery(aCheckboxButton).parent().parent().parent().find('span.'+v).length==0) {
            jQuery(aCheckboxButton).attr('class',v);
            jQuery(aCheckboxButton).attr('checked',true);
            optionsCheckboxClicked(aCheckboxButton,color_codes[v.substring(14)]);
            return false;
            }
          });
        } else {
        jQuery(aCheckboxButton).find('input').removeAttr('checked');
        }
      }
    });
}
问题是,我需要创建一个函数,在调用时重置所有复选框。比如重置复选框。因此,它将清除jQuery内存中的所有值


我不是javascript程序员,您能帮我吗?

您应该为所有复选框(例如checkbox)分配一个类,这样您就可以在一次调用中获取所有复选框,如$.checkbox,然后立即应用所有更改,将所有值设置为默认值。

尝试以下操作:

jQuery('body').find(':checkbox').removeAttr('class')

更改变量颜色_代码=[];到var color_code={};。你的意思是重置复选框颜色吗?我需要重置jQuery内存中存储的所有值,包括颜色和复选框,只使用一个函数