如果通过 jquery 选中复选框,则不会被选中

发布于 2024-11-05 12:40:46 字数 3229 浏览 0 评论 0原文

  $("#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);
                    }
            }        
        }

    });

     });

抱歉,伙计们,我在这个问题上做得不好......正如你所看到的,我 $('#diamond_options')[0].reset();这导致了我评论过的所有问题,一切都有效......

  $("#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);
                    }
            }        
        }

    });

     });

sorry fellas my bad on this problem ....as you can see I $('#diamond_options')[0].reset(); which was causing all the problems i have commented that an it all works....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-11-12 12:40:46

更好地处理最新的 jQuery v1.6 方法 jQuery.prop 和 < a href="http://api.jquery.com/removeprop/" rel="nofollow">jQuery.removeProp

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

Better to deal with latest jQuery v1.6 methods jQuery.prop and jQuery.removeProp

$("#round").prop("checked", true);
$('#round').removeProp('checked') ;    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文