Sweetalert2 的多种输入类型
multiple types of input with Sweetaleart2
我正在尝试使用 html 创建的 Sweetalert2 从多个输入中获取值。
swal({
type: 'question',
title: 'Confirm recipient details',
html: '<p style="color:#C00; padding-bottom:0px; margin-bottom:0px">
Cloud only terms and conditions</p>
<div class="swal_input_wrapper">
<div class="label_wrapper">Email: </div>
<input id="swal-input1" style="width:75%" class="swal2-input" autofocus><br/>
<div class="label_wrapper">Recipient: </div>
<input id="swal-input2" style="width:75%" class="swal2-input"></div><br/>
<div class="label_wrapper">Message: </div>
<textarea id="swal-input3" style="width:75%" class="swal2-textarea"></textarea>
</div>',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val(),
$('#swal-input3').text()
]);
});
}
}).then(function(result) {
//values from inputs (results is an array)
email = result[0];
email_name = result[1];
email_message = result[2];
alert(email_name);
}).done();
测试输出,因为我添加了部分,一切正常,直到我添加 'email_message = result[2];',这表明它无法解析文本区域的值。我尝试使用以下方法从文本区域获取文本,但都没有成功...
$('#swal-input3').text()
$('#swal-input3').val()
$('#swal-input3').html()
在我添加该行之前,警报 (email_name) 有效,但之后它停止了,没有我能找到的错误或警告。
请注意,上面的 html 部分在我的脚本中没有换行符,我添加它们是为了让我的代码更容易阅读,因为这里的代码部分似乎不支持自动换行。
$('#swal-input3').val()
工作正常:[JSFIDDLE]
.val()
是获取文本区域字段值所需要的。
我正在尝试使用 html 创建的 Sweetalert2 从多个输入中获取值。
swal({
type: 'question',
title: 'Confirm recipient details',
html: '<p style="color:#C00; padding-bottom:0px; margin-bottom:0px">
Cloud only terms and conditions</p>
<div class="swal_input_wrapper">
<div class="label_wrapper">Email: </div>
<input id="swal-input1" style="width:75%" class="swal2-input" autofocus><br/>
<div class="label_wrapper">Recipient: </div>
<input id="swal-input2" style="width:75%" class="swal2-input"></div><br/>
<div class="label_wrapper">Message: </div>
<textarea id="swal-input3" style="width:75%" class="swal2-textarea"></textarea>
</div>',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val(),
$('#swal-input3').text()
]);
});
}
}).then(function(result) {
//values from inputs (results is an array)
email = result[0];
email_name = result[1];
email_message = result[2];
alert(email_name);
}).done();
测试输出,因为我添加了部分,一切正常,直到我添加 'email_message = result[2];',这表明它无法解析文本区域的值。我尝试使用以下方法从文本区域获取文本,但都没有成功...
$('#swal-input3').text()
$('#swal-input3').val()
$('#swal-input3').html()
在我添加该行之前,警报 (email_name) 有效,但之后它停止了,没有我能找到的错误或警告。
请注意,上面的 html 部分在我的脚本中没有换行符,我添加它们是为了让我的代码更容易阅读,因为这里的代码部分似乎不支持自动换行。
$('#swal-input3').val()
工作正常:[JSFIDDLE]
.val()
是获取文本区域字段值所需要的。