Bootbox not is not showing pop up modal

喜你入骨 提交于 2019-12-25 03:22:23

问题


I have downloaded bootbox.js in my project and implemented this code to show the pop up modal dialog but nothing errors or success result is printed in my console.I am getting confusing where the error is generated.

Js file

$('switch input[type="checkbox"]').on('change',function(){

        var checkbox=$(this);
        var checked=checkbox.prop('checked');
        var dMsg=(checked)? 'You want to activate the product':
                             'You want to deactivate the product';
        var value=checkbox.prop('value');

        bootbox.confirm({
            size: 'medium',
            title: 'Product Activation & Deactivation',
            message: dMsg,
            callback: function(confirmed){

                if(confirmed){
                    console.log(value);
                    bootbox.alert({
                        size: 'medium',
                        title: 'Information',
                        message : 'you are going to perform operation on product'+ value

                    });
                }
                else{
                    checkbox.prop('checked',!checked);
                }
            }

        });

    });

html file

 <!-- toggle switch -->
        <label class="switch">
            <input type="checkbox" checked="checked" value="4" />
            <div class="slider"></div>
        </label>

回答1:


You have used the wrong selector. You used tag instead of class for 'switch'. You need to use

$('.switch input[type="checkbox"]')

instead.

Ref. https://api.jquery.com/category/selectors/

Also, make sure you have added the dependencies - jquery and bootstrap. Working version - http://jsfiddle.net/grrakesh4769/85etyhfc/3/



来源:https://stackoverflow.com/questions/51502783/bootbox-not-is-not-showing-pop-up-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!