#javascript #jquery #sweetalert2
#javascript #jquery #sweetalert2
Вопрос:
Я использую библиотеку под названием SweetAlert. Я хочу загрузить функцию после того, как пользователь закрыл модальный.
Мой код в настоящее время:
Swal.fire({
imageUrl: 'https://placeholder.pics/svg/600x600',
imageWidth: 600,
imageHeight: 600,
confirmButtonText: 'Jai compris'
}).then(('load', function (event) {
var $this = $(this);
$this.text('...');
var $imageSection = $this.closest('.image-section');
var $colorThiefOutput = $imageSection.find('.color-thief-output');
var $targetimage = $imageSection.find('.target-image');
showColorsForImage($targetimage, $imageSection);
}));
Console.log:
the variables are not defined
код, работающий с нажатием на кнопку :
Swal.fire({
imageUrl: 'https://placeholder.pics/svg/600x600',
imageWidth: 600,
imageHeight: 600,
confirmButtonText: 'jai compris'
}).then((result) => {
$('.run-functions-button').click('load', function (event) {
//Swal.fire('Any fool can use a computer')
var $this = $(this);
$this.text('...');
var $imageSection = $this.closest('.image-section');
var $colorThiefOutput = $imageSection.find('.color-thief-output');
var $targetimage = $imageSection.find('.target-image');
showColorsForImage($targetimage, $imageSection);
});
});
Мой вопрос в том, почему мои переменные не определены? Нажатие на кнопку является обязательным для загрузки функции?
Комментарии:
1. Какие переменные не определены?
Ответ №1:
Swal.fire({
imageUrl: 'https://placeholder.pics/svg/600x600',
imageWidth: 600,
imageHeight: 600,
confirmButtonText: 'Jai compris'
}).then(('load', function (event) {
var $this = $('.run-functions-button');
$this.text('...');
var $imageSection = $this.closest('.image-section');
var $colorThiefOutput = $imageSection.find('.color-thief-output');
var $targetimage = $imageSection.find('.target-image');
showColorsForImage($targetimage, $imageSection);
}));