如果通过jquery进行检查,则选中复选框

时间:2011-05-09 05:11:06

标签: jquery dom checkbox checked

  $("#submit_load").click(function() {

   var  profilename =$("#search_profiles option:selected").attr("value");
    var data='profilename='+profilename+'&user_id=' + <?=$user_id;?>;
    alert(data);
$.ajax({
        //this is the php file that processes the data and send mail
        url: "getprofile.php",  
        type: "POST",
        data: data,     
        cache: false,
        success: function (html) {
        alert(html);
        var dia_info  = html.split('~');
         //$('#diamond_options')[0].reset();

    var dia_id = $(':checkbox:checked.ds_nobg').map(function() {
           return this.id;
         }).get().join(',');
      alert("diatype----"+dia_id);
        // alert(dia_id.length);
         if(dia_id.length>0)
         {
             var dia_id_arr  = dia_id.split(',');
            for(var j=0;j<dia_id_arr.length;j++)
            {

                 var chk_id = dia_id_arr[j];



                  var diashape_chk = '#' + chk_id;
                   var bg_id='#'+chk_id+'1';
                    var shape_id='#'+chk_id+'-1';
                    var shape_class_on=chk_id+'_1_on';
                    var shape_class_off=chk_id+'_1';

               // alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
              //  alert(dia_id_arr_sp[0]+'---'+dia_id_arr_sp[1]+'---'+diashape_chk+'---'+diashape+'---'+remclass+'---'+addcls+'---'+rembg );

            //  alert(diashape);
                $(shape_id).removeClass(shape_class_on);
            $(shape_id).addClass(shape_class_off);  
            $(bg_id).removeClass('ds_bg_hi' );
            $(bg_id).addClass('ds_nobg' );
            $(diashape_chk).removeAttr('checked') ;
             if ($(shape_id).hasClass(shape_class_off)) {
                        alert("helllo---"+j+"---"+shape_id);
                    }
            }        
        }
     if(dia_info[34].length>0)
         {


             var dia_id_arr  = dia_info[34].split(',');
            for(var l=0;l<dia_id_arr.length;l++)
            {

                  var chk_id = dia_id_arr[l];


                  var diashape_chk = '#' + chk_id;
                 var bg_id='#'+chk_id+'1';
                    var shape_id='#'+chk_id+'-1';
                    var shape_class_on=chk_id+'_1_on';
                    var shape_class_off=chk_id+'_1';

                    if ($(shape_id).hasClass(shape_class_off)) {
                        alert("ddddd---"+l+"---"+shape_id);
                    }



                   // alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
                $(shape_id).removeClass(shape_class_off);
            $(shape_id).addClass(shape_class_on);   
            $(bg_id).removeClass('ds_nobg' );
            $(bg_id).addClass('ds_bg_hi' );
            $(diashape_chk).attr('checked', 'checked') ;
             if ($(shape_id).hasClass(shape_class_on)) {
                        alert("eeee---"+l+"---"+shape_id);
                    }
            }        
        }

    });

     });
抱歉,我对这个问题表示不满......你可以看到I $('#diamond_options')[0] .reset();这引起了我所评论的所有问题,这一切都有效......

1 个答案:

答案 0 :(得分:0)

最好处理最新的 jQuery v1.6 方法jQuery.propjQuery.removeProp

$("#round").prop("checked", true);
$('#round').removeProp('checked') ;