2016-04-04 64 views
0

我已经为sweetalert定义了以下对话框。一切工作正常,但复选框没有出现。还有什么我需要改变? 我已经足够的搜索,但没有找到任何解决方案。html文本中的输入类型复选框不起作用

Sweetalert对话框:

swal({ title: "Are you sure?", text:" <form><input type='checkbox' name='vehicle' value='Bike'>I have a bike<br></form> Workload will be validated by you for cbs merge! <div class='text-danger'>" +wl_name+ "</div>" , 
            showCancelButton: true, type: "info", 
            confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, validate it!", cancelButtonText: "No, cancel pleaase!", 
            closeOnConfirm: false, closeOnCancel: false, html:true , showLoaderOnConfirm: true},) 

所有其它的HTML标签正在fine..only此复选框不上sweetalert弹出模型可见。

如果您需要更多信息,请让我知道。

回答

2

SweetAlert不支持自定义表单输入,但SweetAlert2确实:),不知道他们的CSS怎么回事。

JSFIDDLE

$('document').ready(function() { 
    $(document).on('click', '.test', function() { 
    swal({ 
     title: "Are you sure?", 
     html: '<form><input type="checkbox">I have a bike<br></form> Workload will be validated by you for cbs merge! <div class="text-danger">test</div>', 
     showCancelButton: true, 
     type: "input", 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Yes, validate it!", 
     cancelButtonText: "No, cancel pleaase!", 
     closeOnConfirm: true, 
     closeOnCancel: true, 
     showLoaderOnConfirm: true, 
    }); 
    }); 
}); 
+0

改变'类型: “输入”,'来'输入:'复选框','应该修复样式问题。 'type'切换模式类型图标,而'input'切换输入类型。 – Winfried

2

有一个在SweetAlert2使用checkbox模态型的好方法:

swal({ 
 
    title: 'Do you have a bike?', 
 
    input: 'checkbox', 
 
    inputPlaceholder: 'I have a bike' 
 
}).then(function(result) { 
 
    if (result.value) { 
 
    swal({type: 'success', text: 'You have a bike!'}); 
 

 
    } else if (result.value === 0) { 
 
    swal({type: 'error', text: "You don't have a bike :("}); 
 

 
    } else { 
 
    console.log(`modal was dismissed by ${result.dismiss}`) 
 
    } 
 
})
<script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>

+0

多选复选框和复选框选择? @limonte –

+0

这对我来说非常合适。 – Ciprian

+0

不适用于我。在我的情况下,如果选中'result'将为1,未选中0。 'result.value'未定义 –

相关问题