【发布时间】:2018-11-14 04:15:52
【问题描述】:
我想知道是否可以在同一个甜蜜警报中同时允许选择下拉列表和输入文本区域。
例如:我的选择列表有 4 个选项,最后一个选项是其他选项。我想当用户选择其他人时,它会显示一个文本区域供用户输入。我正在使用类似于 sweetalert 2 给出的内容,如下所示。
swal({
title: 'Select field validation',
input: 'select',
inputOptions: {
'apples': 'Apples',
'bananas': 'Bananas',
'grapes': 'Grapes',
'Others': 'Others'
},
inputPlaceholder: 'Select a fruit',
showCancelButton: true,
inputValidator: (value) => {
return new Promise((resolve) => {
if (value === 'oranges') {
resolve()
} else {
resolve('You need to select oranges :)')
}
})
}
})
if (fruit) {
swal('You selected: ' + fruit)
}
【问题讨论】: