Javascript 如何在显示sweetalert弹出消息时使复选框值不更改
我有一个复选框,它有一个基本值。我想让用户可以通过单击复选框中的选项来更改该值,然后显示警报消息以确保他们是否要更改该值。如果是,则复选框值正在更改,如果不是,则复选框值不会更改 我曾尝试使用Javascript 如何在显示sweetalert弹出消息时使复选框值不更改,javascript,jquery,codeigniter,sweetalert2,Javascript,Jquery,Codeigniter,Sweetalert2,我有一个复选框,它有一个基本值。我想让用户可以通过单击复选框中的选项来更改该值,然后显示警报消息以确保他们是否要更改该值。如果是,则复选框值正在更改,如果不是,则复选框值不会更改 我曾尝试使用sweetalert插件构建它。现在的问题是,当用户单击复选框值更改值,然后显示sweetalert弹出窗口时,复选框值已经更改。因此,即使用户在sweetalert模式中单击了no选项,我也需要重新加载页面 如何使复选框值仅在用户单击sweetalert模式中的yes选项后更改 这是查看代码 <di
sweetalert
插件构建它。现在的问题是,当用户单击复选框值更改值,然后显示sweetalert
弹出窗口时,复选框值已经更改。因此,即使用户在sweetalert
模式中单击了no
选项,我也需要重新加载页面
如何使复选框
值仅在用户单击sweetalert
模式中的yes
选项后更改
这是查看代码
<div class="col-lg-6">
<!--begin::Card-->
<div class="card card-custom gutter-b example example-compact">
<div class="card-header">
<h3 class="card-title">General</h3>
</div>
<div class="card-body" style="height:80px">
<div class="checkbox-inline">
<label class="checkbox">
<input type="checkbox" name="Checkboxes2" id="checkbox1" onclick='editGeneral(this.value)'/>
<span></span>
Checkin Status
</label>
</div>
</div>
</div>
<!--end::Card-->
</div>
一般的
签入状态
下面是ajax代码
function editGeneral(){
Swal.fire({
text: "Are you sure to change this ?",
icon: "warning",
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes!',
cancelButtonText: 'No'
}).then((result) => {
if(result.isConfirmed) {
var tes = $("#checkbox1").is(":checked");
$.ajax({
url: "<?php echo base_url(); ?>contoller/changefunction",
type:"POST",
dataType:"json",
data:{"config_value":tes},
success: function(response){
Swal.fire({
title: 'Success',
text: 'Status has been changed',
icon: 'success',
timer: 2000,
showCancelButton: false,
showConfirmationButton: false,
}).then((hasil) => {
location.reload();
});
}
})
}else{
Swal.fire({
timer: 10,
showCancelButton: false,
showConfirmationButton: false,
}).then((hasil) => {
location.reload();
});
}
});
}
函数editGeneral(){
喷火({
文本:“您确定要更改此选项吗?”,
图标:“警告”,
showCancelButton:true,
confirmButtonColor:“#3085d6”,
cancelButtonColor:“#d33”,
confirmButtonText:“是!”,
cancelButtonText:“否”
})。然后((结果)=>{
如果(结果已确认){
变量tes=$(“#checkbox1”)。是(“:checked”);
$.ajax({
url:“控制/更改功能”,
类型:“POST”,
数据类型:“json”,
数据:{“配置值”:tes},
成功:功能(响应){
喷火({
标题:"成功",,
文本:“状态已更改”,
图标:“成功”,
计时器:2000,
showCancelButton:false,
showConfirmationButton:false,
}).然后((hasil)=>{
location.reload();
});
}
})
}否则{
喷火({
计时器:10,
showCancelButton:false,
showConfirmationButton:false,
}).然后((hasil)=>{
location.reload();
});
}
});
}
谢谢我已经修改了您的代码,使其在这里工作,您可以看到,我将所有复选框作为
onclick='editGeneral(this)
传递,因此当甜蜜通知确认与否时,我将根据您的选择更改复选框
功能编辑概述(el){
喷火({
文本:“您确定要更改此选项吗?”,
图标:“警告”,
showCancelButton:true,
confirmButtonColor:“#3085d6”,
cancelButtonColor:“#d33”,
confirmButtonText:“是!”,
cancelButtonText:“否”
})。然后((结果)=>{
如果(结果已确认){
(el.checked)?el.checked=真:el.checked=假;
/*
$.ajax({
url:“控制/更改功能”,
类型:“POST”,
数据类型:“json”,
数据:{“配置值”:tes},
成功:功能(响应){
喷火({
标题:"成功",,
文本:“状态已更改”,
图标:“成功”,
计时器:2000,
showCancelButton:false,
showConfirmationButton:false,
}).然后((hasil)=>{
location.reload();
});
}
})
*/
}否则{
(el.checked)?el.checked=假:el.checked=真;
喷火({
计时器:10,
showCancelButton:false,
showconfixton:false,
}).然后((hasil)=>{
//location.reload();
});
}
});
}
一般的
签入状态