加载设置甜蜜警报输入的值

时间:2017-07-21 08:45:11

标签: sweetalert

在甜蜜警报2中,如何在加载时设置输入值 我的甜蜜警报代码

swal({
              title: 'Are you sure?',
              text: "You are going to send emails from the system. Please confirm",                   
              showCancelButton: true,
              input: 'email',

              confirmButtonText: 'Submit',
              confirmButtonColor: '#4aa0f1',
              cancelButtonColor: '#898b8e',
              confirmButtonText: 'Send'
            }).then(function (email) {  
                send_email = email;
                sentHtmtBody_send();
                loadingIcon();
            });

2 个答案:

答案 0 :(得分:2)

我们可以添加另一个字段

inputValue : 'test value',

添加完整代码后,我们可以看到它像这样

swal({
              title: 'Are you sure?',
              text: "You are going to send emails from the system. Please confirm",                   
              showCancelButton: true,
              input: 'email',
              inputValue: "E.g john",
              confirmButtonText: 'Submit',
              confirmButtonColor: '#4aa0f1',
              cancelButtonColor: '#898b8e',
              confirmButtonText: 'Send'
            }).then(function (email) {  
                send_email = email;
                sentHtmtBody_send();
                loadingIcon();
            });

答案 1 :(得分:1)

在sweetalert2上,我在此suggested way中实现了它:

let input = document.createElement("input");
input.value = 'test';
input.type = 'text';
input.className = 'swal-content__input';
swal('Please type:', {
    content: input,
    buttons: ['Cancel', 'Update']
})
.then(() => {
    //
});