【问题标题】:Before showing next div on click check atleast 1 checkbox should be checked在单击检查显示下一个 div 之前,应检查至少 1 个复选框
【发布时间】:2016-11-17 05:16:37
【问题描述】:

我有以下要求,在显示下一个 div 之前必须检查至少 1 个复选框,否则必须检查单选。 完成了,但是,如果用户选择窗口 ac 并选择所有 4 项服务,则应在 nxet 按钮上询问所有选定服务的 no of unist。最后显示booknow按钮。如果他选择 2 项服务,那么它会询问两个所选服务的单元数如果他同时选择窗口和拆分 ac,然后选择服务数,那么它会询问用户对于窗口和拆分类型的所选服务的单元数。

提前致谢。

我的代码如下

 <div class="container quick-box-outer">
            <div class="voffset-7">
                <div class="col-md-12">
                    <div class="panel panel-warning first current" id="step1">
                        <div class="panel-heading">What we provide</div>
                        <div class="panel-body">
                            <ul class="services-list">
                                <li>Background checked and trained technicians</li>
                                <li>30 days service guarantee</li>
                            </ul>
                        </div>
                        <div class="panel-heading">Pricing</div>
                        <div class="panel-body">
                            <ul class="services-list">
                                <li>Fixed charges for installation, uninstallation and servicing</li>
                                <li>Charges for AC repairs will be quoted upon inspection</li>
                                <li>Rs.199 inspection charges if no service is availed post inspection</li>
                            </ul>
                        </div>
                    </div>
                    <div class="panel panel-warning" id="step2" style="display:none">
                        <div class="panel-heading">What do you need?</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <input type="checkbox" name="windowac" id="windowac" class="mychk">
                                    <label for="windowac"> Window AC</label>
                                </div>
                            </div>
                            <div class="col-sm-12">
                                <div class="select-product last">
                                    <input type="checkbox" id="splitac" name="fliptac" class="mychk">
                                    <label for="splitac">Split AC</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning" id="step3" style="display:none">
                        <div class="panel-heading">What type of service do you want?</div>
                        <div class="panel-body">
                            <form id="step2">
                                <div class="col-sm-12">
                                    <div class="select-product">
                                        <input type="checkbox" name="wetservice" id="wetservice" class="mychk">
                                        <label for="wetservice"> Wet Servicing (Jet pump service not included)</label>
                                    </div>
                                    <div class="select-product">
                                        <input type="checkbox" name="dryservice" id="dryservice">
                                        <label for="dryservice"> Dry Servicing</label>
                                    </div>
                                    <div class="select-product">
                                        <input type="checkbox" name="gas" id="gas">
                                        <label for="gas"> Gas Charging</label>
                                    </div>
                                    <div class="select-product last">
                                        <input type="checkbox" name="other" id="other">
                                        <label for="other"> Other repairs</label>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>

                    <div class="panel panel-warning last" id="step4" style="display:none">
                        <div class="panel-heading">How many ACs need Wet servicing?</div>
                        <div class="panel-body">
                            <form id="step2">
                                <div class="col-sm-12">
                                    <div class="select-product">
                                        <label for="1unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="2unit">
                                            <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="3unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="4unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product last">
                                        <label for="5unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step5" style="display:none">
                        <div class="panel-heading">How many ACs need Dry servicing?</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step6" style="display:none">
                        <div class="panel-heading">How many ACs need Gas Charging</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step7" style="display:none">
                        <div class="panel-heading">How many ACs need other reparing</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="panel-footer">
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <button type="submit" class="btn btn-raised btn-warning" id="prev" style="display:none;">Back</button>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <a href="javascript:;" class="btn btn-raised btn-warning pull-right" id="next">Next</a>
                            <a href="javascript:;" class="btn btn-raised btn-warning pull-right" id="booknow" style="display:none;">Book Now</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <script type="text/javascript">
    $('#next').click(function() {

        if ($('.current').find(':checkbox,:radio').length > 0 && !$('.current :checked').length) {
            alert('Select one or more options to Continue')
            return;
        }
        $('.current').removeClass('current').hide()
            .next().show().addClass('current');
        if ($('.current').hasClass('last')) {
            $('#next').hide();
            $('#booknow').show();
        }
        $('#prev').show();
    });

    $('#prev').click(function() {
        $('#booknow').hide();
        $('.current').removeClass('current').hide()
            .prev().show().addClass('current');
        if ($('.current').hasClass('first')) {
            $('#prev').hide();
        }
        $('#next').show();
    });

</script>
<script>
    $('#booknow').click(function() {
        if ($('.current').find(':checkbox,:radio').length > 0 && !$('.current :checked').length) {
            alert('Select one or more options to Continue')
            return;
        }
        window.location = "checkout.html"
    });

</script>

【问题讨论】:

    标签: jquery html css next


    【解决方案1】:

    您可以检查当前框是否有单选元素和复选框,如果是,则检查选中元素的长度。像这样:

    if( $('.current').find(':checkbox,:radio').length > 0  &&  !$('.current :checked').length){
       alert('check atleast one item')
       return;
    }
    

    sn-p 需要在下一个按钮单击和现在预订按钮单击处理程序中添加。

    Working Demo

    【讨论】:

    • 您好 Milind,它适用于所有“下一步”按钮,但不适用于“立即预订”按钮
    • @Vishaal:您需要为现在预订按钮添加点击事件。满足上述条件时进行重定向。
    • @Vishaal :因为,验证是针对带有 id = next 而不是 id="booknow" 的按钮
    • 你好 Milind,我已经添加了点击,现在它正在工作。
    • @Vishaal:太好了……别忘了接受答案:)
    【解决方案2】:

    你好,检查一下,你可以根据长度检查 $('.current').find(':checkbox,:radio').length

    https://plnkr.co/edit/98wqVnVnBMvlh1idgM94?p=preview

    【讨论】:

    • 它适用于所有 NEXT 按钮,但不适用于“立即预订”按钮
    【解决方案3】:
       if($('.current input[type=checkbox]:checked').length)
                {
                    //go next
                } else
                {
                  alert('select atleast one checkbox')
                } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 2012-10-17
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      相关资源
      最近更新 更多