我已经在我的项目中下载了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>发布于 2018-07-25 00:01:09
您使用了错误的选择器。您为“switch”使用了标记而不是class。您需要使用
$('.switch input[type="checkbox"]')而不是。
参考https://api.jquery.com/category/selectors/
另外,确保添加了依赖项- jquery和bootstrap。工作版本- http://jsfiddle.net/grrakesh4769/85etyhfc/3/
https://stackoverflow.com/questions/51502783
复制相似问题