2017-03-23 22 views
0
swal({ 
title: 'Please Select a contact to send money', 
input: 'select', 
inputOptions: { 
'1': 'Jhon', 
'2': 'Gemie', 
'3': 'Paul' 
}, 
inputPlaceholder: 'Select a contact', 
html: 'Amount: <input id="amount" class="form-control swal2-input">', 
preConfirm: function() { 
return new Promise(function (resolve) { 
    resolve(
     document.getElementById('amount').value, 
    ) 
}) 
} 
onOpen: function() { 
$('#swal-input1').focus() 
} 
}).then(function (result) { 
swal(JSON.stringify(result)) 
}).catch(swal.noop) 

上記のコードは結果としてテキスト入力値のみを表示しています。結果配列の選択値も取得できますか。私はSweetAlert2を使用します。ありがとう!!選択フィールドとカスタム入力は結果として入力値のみを表示します。sweetalert2

答えて

2

preConfirm関数の最初のパラメータは、選択したオプションの値にする必要があります。

swal({ 
 
    title: 'Please Select a contact to send money', 
 
    input: 'select', 
 
    inputOptions: { 
 
    '1': 'Jhon', 
 
    '2': 'Gemie', 
 
    '3': 'Paul' 
 
    }, 
 
    inputPlaceholder: 'Select a contact', 
 
    html: 'Amount: <input id="amount" class="form-control swal2-input">', 
 
    preConfirm: function (selectedOption) { 
 
    return new Promise(function (resolve) { 
 
     resolve({selectedOption: selectedOption, value: document.getElementById('amount').value}) 
 
    }); 
 
    }, 
 
    onOpen: function() { 
 
    $('#swal-input1').focus(); 
 
    } 
 
}).then(function (result) { 
 
    console.log(result); 
 
    swal(JSON.stringify(result)) 
 
}).catch(swal.noop)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdn.jsdelivr.net/sweetalert2/6.4.4/sweetalert2.min.js"></script> 
 
<link href="https://cdn.jsdelivr.net/sweetalert2/6.4.4/sweetalert2.css" rel="stylesheet"/>

:あなたはこのような何かを行うことができますことを意味

関連する問題