【问题标题】:Bootbox not is not showing pop up modalBootbox not 不显示弹出模式
【发布时间】:2018-07-24 15:44:41
【问题描述】:

我已经在我的项目中下载了 bootbox.js 并实现了此代码以显示弹出模式对话框,但在我的控制台中没有打印任何错误或成功结果。我对生成错误的位置感到困惑。

js文件

$('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文件

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

【问题讨论】:

  • 您的选择器错误;它必须是 $('.switch input[type="checkbox"]'); switch 是一个类
  • 现在它向我显示错误,例如“$st is not defined”

标签: javascript jquery bootbox


【解决方案1】:

您使用了错误的选择器。您使用标签而不是类来“切换”。 你需要使用

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

改为。

参考。 https://api.jquery.com/category/selectors/

另外,请确保您已添加依赖项 - jquery 和 bootstrap。 工作版 - http://jsfiddle.net/grrakesh4769/85etyhfc/3/

【讨论】:

  • 我的 jquery 版本是 3.3.7,我的项目中没有输出.. 请问你可以来团队查看器吗??
  • 提供重现它或小提琴所需的代码。
  • 您在 js fiddle 中提供的代码正在运行,但添加类点我的滑块会更改,但不会出现弹出模式。所以如果你能来teamviewer 5分钟,我会很高兴让你的回答正确,请:(
猜你喜欢
  • 2013-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多