问题
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