Bootbox not is not showing pop up modal

2019-08-28 03:44发布

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条回答
等我变得足够好
2楼-- · 2019-08-28 04:11

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/

查看更多
登录 后发表回答