我不明白单击 btn 文本时如何调用此函数。唯一有效的方法是(async () => { 我尝试过这个$(document).ready(function() {
$('#demo').submit(function(e) {但不起作用。
(async () => {
const { value: file } = await Swal.fire({
title: 'Select image',
input: 'file',
inputAttributes: {
'accept': 'image/*',
'aria-label': 'Upload your profile picture'
}
})
if (file) {
const reader = new FileReader()
reader.onload = (e) => {
Swal.fire({
title: 'Your uploaded picture',
imageUrl: e.target.result,
imageAlt: 'The uploaded picture'
})
}
reader.readAsDataURL(file)
}
})()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<button class="form-control cal " id="demo">
Try me!
</button>
SMILET
相关分类