测验测试-icheck jquery

时间:2015-04-10 07:25:01

标签: jquery icheck

我有这段代码:

   <div class="item active">
                            <div class="intrebare form-group">
                                <p>Q1. Le este usor consumatorilor cu care ati interactionat sa diferentieze intre pachetele de MLB?</p>
                                <div class="raspuns checkbox"> 
                                    <label class="chk"><input type="radio" class="CF_custom_chk" name="mr_red_q1" data-error="Before you wreck yourself" required value="Da">  <span>Da</span></label>
                                    <label class="chk"><input type="radio" class="CF_custom_chk" name="mr_red_q1" data-error="Before you wreck yourself" required value="Nu">  <span>Nu</span></label>
                                </div>
                                <div class="help-block with-errors"></div>
                            </div>
                            <div class="intrebare form-group">
                                <p>Q2. Consumatorul apreciaza noul pachet de Marlboro?</p>
                                <div class="raspuns checkbox"> 
                                    <label class="chk">
                                        <input type="radio" class="CF_custom_chk" name="mr_red_q2" data-error="Before you wreck yourself" required value="Da">  
                                        <span>Da</span>
                                    </label>
                                    <label class="chk nu">
                                        <input data-attr-q2="no" type="radio" class="CF_custom_chk nu" name="mr_red_q2" data-error="Before you wreck yourself" required value="Nu">  
                                        <span>Nu</span>
                                    </label>
                                    <label class="chk">
                                        <input type="radio" class="CF_custom_chk" name="mr_red_q2" data-error="Before you wreck yourself" required value="Nu se aplica">  
                                        <span>Nu se aplica</span>
                                    </label>
                                    <div class="ascuns">
                                        <label class="chk">
                                            <input type="radio" class="CF_custom_chk CF_custom_chk_hide" name="mr_red_q2_a" data-error="Before you wreck yourself" required value="Le placea pachetull vechi">  
                                            <span>Le placea pachetul vechi</span>
                                        </label>
                                        <label class="chk">
                                            <input type="radio" class="CF_custom_chk CF_custom_chk_hide" name="mr_red_q2_a" data-error="Before you wreck yourself" required value="Nu e o schimbare mare">  
                                            <span>Nu e o schimbare mare</span>
                                        </label>
                                        <label class="chk">
                                            <input type="radio" class="CF_custom_chk CF_custom_chk_hide" name="mr_red_q2_a" data-error="Before you wreck yourself" required value="Cartonul pachetului">  
                                            <span>Cartonul pachetului</span>
                                        </label>
                                        <label class="chk">
                                            <input type="radio" class="CF_custom_chk CF_custom_chk_hide" name="mr_red_q2_a" data-error="Before you wreck yourself" required value="Nici una din cele de mai sus">  
                                            <span>Niciuna din cele de mai sus</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="help-block with-errors"></div>
                            </div>
                        </div>

这是一个测验,一切正常,但是当我检查从按钮到顶部的单选按钮时,一切都坏了。我想这样的事情:当我在第一个问题中检查是或否,我的下一个按钮被隐藏。在那之后,当我检查是或者在第二个问题中,我的按钮旁边是可见的。重要提示:必须在第一个问题中检查一个单选按钮!如果检查了第一个问题的任何单选按钮,并且我从第二个问题检查了带有val()== no的按钮,则将显示另一个div,并且将隐藏下一个按钮。检查此div中的任何值后,将显示下一个按钮。 Q();

          function q(last) {
                var last = last;
                //fdgdf

            // if($('.item.active .ascuns').length==2){
            //     console.log($('.item.active .ascuns'));
            // }

            //fsdfdsfds
                 $('.item.active input[type=radio]').on('ifChecked', function (event) {
                    if( ($(this).val() === "Nu" && $(this).attr('data-attr-q2') === 'no') || 
                        ($(this).attr('data-attr-red-q3') === 'no' && $(this).val() === "Nu") ||
                        ($(this).attr('data-attr-red-q4') === 'no' && $(this).val() === "Nu")
                    ) { 
                        $('.next').hide();
                        $('.next').css('display', 'none');

                        $(this).parent().parent().parent().find(".ascuns").show();

                        $('.item.active .ascuns input[type=radio]').on('ifChecked', function (event) {                           
                            if(!last) {
                                $('.next').show();
                                $('.next').css('display', 'block');
                            }                            
                        });                        
                    }else{        
                         $(this).parent().parent().parent().find(".ascuns").hide();
                        $('.item.active .ascuns .icheckbox_minimal-blue') .removeClass('checked');
                        if($('.item.active .intrebare .raspuns .ascuns').length == 1) {

                             if ($('.carousel-inner .item.active .icheckbox_minimal-blue.checked').length == 1) {  
                                     $('.next').show();
                                     $('.next').css('display', 'block');
                             }                                                          
                        } else if($('.item.active .intrebare .raspuns .ascuns').length == 2) {
                             if ($('.carousel-inner .item.active .icheckbox_minimal-blue.checked').length >= 2) {  
                                     $('.next').show();
                                     $('.next').css('display', 'block');
                             }                                                          
                        }             
                    }             
                });


            }
var count = 0;

            var $oCarousel = $('#carousel-example-generic');
            var $myCarouselIndicators = $oCarousel.find('.carousel-indicators li');

            var slideCount = $myCarouselIndicators.length;

            $('#carousel-example-generic').on('slid.bs.carousel', function () {
                var index = $myCarouselIndicators.filter('.active').data('slide-to');
                if (index === 0) {
                    $('.next').css('display', 'none');
                } else if (index === slideCount - 1) {
                    q(true);
                    $('.next').css('display', 'none');

                } else {
                    q(true);
                    $('.next').css('display', 'none');
                }

                count++;
                if (count ==2) {                
                    q(true);
                    $('.next').css('display', 'none');
                    $('.finish').css('display', 'block');
                }
            });

0 个答案:

没有答案