是否可以在sweetAlert框中添加复选框?

时间:2018-02-14 07:35:05

标签: sweetalert

我可以将inputType设置为密码。支持的其他输入类型是什么?

       swal({
            title: "Are you sure?",             
            type: "input",
            inputType: "checkbox",             
            showCancelButton: true,
            closeOnConfirm: true,                
        }, function () {
            swal("", "You did it", "success");
        });

swal支持复选框inputType。

1 个答案:

答案 0 :(得分:2)

SweetAlert2中使用checkbox模态类型的方法很简单:

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

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

  } else {
    console.log(`modal was dismissed by ${result.dismiss}`)
  }
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>

PS。请注意,SweetAlert2与SweetAlert略有不同,请查看简单的迁移指南:https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2