我不明白如何添加 textarea
类型
在 sweet
警报中。
类似于 type: "input"
$('#saveBtn).click(function(){
swal({
title: "Enter your Name!",
text: "your name:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
animation: "slide-from-top",
inputPlaceholder: "Write something" },
function(inputValue){
if (inputValue === false)
return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
swal("Nice!", "You wrote: " + inputValue, "success");
});
});
这很好用。但是如果我使用 type: "textarea"
而不是 type: "input"
这给出了这样的错误:
sweetalert.min.js:1 Uncaught ReferenceError: logStr is not defined
感谢您的帮助。
最佳答案
原始的 SweetAlert 插件目前不受支持,您可能看不到其中的文本区域功能。我创建了 SweetAlert2它具有 textarea
功能:
Swal.fire({
title: 'Input something',
input: 'textarea'
}).then(function(result) {
if (result.value) {
Swal.fire(result.value)
}
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
Textarea example in SweetAlert2 documentation ↗
从 SweetAlert 到 SweetAlert2 的转换很简单,这里是 migration guide .
关于javascript - 如何使用 jQuery 在 sweet alert 中添加 textarea 标签作为输入元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790965/