【发布时间】: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