如何解决在sweetalert中选择取消后的单选按钮选择
我有 4 个带有单选按钮的选项,我想将它们与 Sweetalert 结合使用。用户有 1 个来自数据库的默认值。
如果用户想改变选择,它会显示警报确认。如果用户点击是,它会改变,并保存到数据库中,如果用户点击否,选择不会改变。
当用户在 Sweetalert 确认中单击 no 时,我无法做出选择不改变的问题。在这个
这是 HTML 代码
<input type="hidden" id="vbadgeVal">
<table class="table table-bordered">
<tbody>
<tr>
<td>
<input type="radio" name="vbadge" value="1" id="vbadge1" onclick="handleClick(this);"><br>
<label>HTML</label>
</td>
<td>
<input type="radio" name="vbadge" value="2" id="vbadge2" onclick="handleClick(this);"><br>
<label>CSS</label>
</td>
</tr>
</tbody>
</table>
这是 JavaScript 代码
$.ajax({
url:"<?= base_url();?>settings/template",type:"GET",success: function(response)
{
$('#vbadgeVal').val(response.data[0].config_value);
if(response.data[0].config_value==1)
{
$("#vbadge1").attr('checked',true)
}else{
$("#vbadge2").attr('checked',true)
}
}
})
function handleClick(el){
var currentValue = el.value;
var oldValue = $('#vbadgeVal').val();
if(currentValue!=oldValue){
if(currentValue=='1'){
Swal.fire({
html: 'Are you sure want to change to "HTML" ? ',showCancelButton: true,showConfirmButton: true
}).then((result) => {
if(result.isConfirmed){
$.ajax({
type: "POST",url: "<?PHP echo base_url(); ?>" + "settings/UpdateTemplate",data: {config_value:currentValue},success: function(response2)
{
Swal.fire({
text: 'Success',icon: 'success',timer: 2000,showConfirmButton: false
}).then((result) => {
location.reload();
});
}
})
}else{
(el.checked) ? el.checked = false : el.checked = true;
}
})
}else if(currentValue=='2'){
Swal.fire({
html: 'Are you sure want change to "CSS" ?',customClass: 'swal-wide',showConfirmButton: true
}).then((result) => {
if(result.isConfirmed){
$.ajax({
type: "POST",success: function(response2)
{
Swal.fire({
text: 'Success',showConfirmButton: false
}).then((result) => {
location.reload();
});
}
})
}else{
(el.checked) ? el.checked = false : el.checked = true;
}
})
}
}
当用户在 Sweetalert 确认模式中选择“否”时,您知道如何让用户选择恢复为默认值吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。