我正在使用这个https://sweetalert.js.org/guides/版本,只是遇到了和你一样的问题
因为我需要坚持 sweetalert1(那些版本)。所以我需要像你问的那样做更多的工作......
这个想法很简单。你一眼就能明白。基本上我的想法是在常规 HTML 上创建一个选择然后隐藏它。然后将生成的选择复制到 Sweet Alert,并在您创建的基本选择中检索结果。
我知道这并不简单而且效率不高:))但我找不到任何其他解决方案(无法升级到 SweetAlert 2)。如果您找到更好的解决方案,请在下方评论!我很感激!
HTML / Laravel
// create dynamic users on html and hide it
<select name="tujuan" id="tujuan-holder" class="hidden chosen-tujuan">
@foreach ($users as $item)
<option value="{{ $item->nama }}">{{$item->nama}}</option>
@endforeach
</select>
Javascript
$(document).ready(function(){
$(".chosen-tujuan").chosen({ //create the chosen
width: "100%",
});
$("#tujuan_holder_chosen").addClass("hidden"); // then hide the chosen bar
}); // if you dont hide it it will show up on your interface not on your swal
$(".btn-process").click(function(){
swal({
title:"Apakah anda sudah mengirimkannya?",
text:"Kepada siapa anda mengirimkan Dokumen ini?",
icon:"warning",
content: { //here is the element will be
element:$("#tujuan_holder_chosen").removeClass("hidden")[0]
}
}).then((result)=>{
alert($("#tujuan-holder").val()); // then retrieve the ouput by collecting the value on your original select, not the chosen,
}); // because chosen create a new interface
});