gpt4 book ai didi

javascript - 突出显示 sweetAlert 中的默认文本输入

转载 作者:数据小太阳 更新时间:2023-10-29 05:21:25 24 4
gpt4 key购买 nike

我有一个 SweetAlert2允许文本输入,我给它一个默认值。我希望在弹出警报时突出显示此默认值,以便用户可以在需要时立即覆盖它。这是一个例子:

enter image description here

这是我使用 sweetAlert 选项调用的函数:

window.sweetPrompt = function (title, message, callback, input, keepopen, allowOutsideClick, allowEscapeKey) {
sweetAlert({
title: title,
text: message,
input: 'text',
confirmButtonColor: "#428bca",
preConfirm: function(text) {
return new Promise(function(resolve) {
if (!keepopen) {
resolve();
} else {
callback(text);
}
});
},
inputValidator: function(text) {
return new Promise(function (resolve, reject) {
if (text) {
resolve();
} else {
reject('Cannot be empty!');
}
});
},
inputValue: input,
showCancelButton: true,
reverseButtons: true,
allowOutsideClick: allowOutsideClick,
allowEscapeKey: allowEscapeKey
}).then(callback, function(dismiss){});
};

我该怎么做(如果可能的话)?我考虑过使用 jQuery,但不确定如何获取对 sweetAlert 对话框的引用。如有任何建议,我们将不胜感激。

最佳答案

给你:

Swal.fire({
input: 'text',
inputValue: 'input value',
didOpen: () => {
Swal.getInput().select()
}
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

附言。请注意,SweetAlert2 和 SweetAlert 是两个不同的项目,API 略有不同。

SweetAlert2 文档:https://sweetalert2.github.io/

关于javascript - 突出显示 sweetAlert 中的默认文本输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44845663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com