Javascript SweetAlert2检测单选按钮选择
我正在使用SweetAlert2JavaScript库来显示弹出窗口。SweetAlert2是SweetAlert的一个分支,不再维护。SweetAlert2允许我添加这样的单选按钮Javascript SweetAlert2检测单选按钮选择,javascript,jquery,sweetalert,sweetalert2,Javascript,Jquery,Sweetalert,Sweetalert2,我正在使用SweetAlert2JavaScript库来显示弹出窗口。SweetAlert2是SweetAlert的一个分支,不再维护。SweetAlert2允许我添加这样的单选按钮 // inputOptions can be an object or Promise var inputOptions = new Promise(function(resolve) { resolve({ '#ff0000': 'Red', '#00ff00': 'Green',
// inputOptions can be an object or Promise
var inputOptions = new Promise(function(resolve) {
resolve({
'#ff0000': 'Red',
'#00ff00': 'Green',
'#0000ff': 'Blue'
});
});
swal({
title: 'Select color',
input: 'radio',
inputOptions: inputOptions,
inputValidator: function(result) {
return new Promise(function(resolve, reject) {
if (result) {
resolve();
} else {
reject('You need to select something!');
}
});
}
}).then(function(result) {
swal({
type: 'success',
html: 'You selected: ' + result
});
})
<input id="swal2-radio-1" type="radio" name="swal2-radio" value="3">
SweetAlert2为无线电输入指定“swal2无线电”名称,如下所示
// inputOptions can be an object or Promise
var inputOptions = new Promise(function(resolve) {
resolve({
'#ff0000': 'Red',
'#00ff00': 'Green',
'#0000ff': 'Blue'
});
});
swal({
title: 'Select color',
input: 'radio',
inputOptions: inputOptions,
inputValidator: function(result) {
return new Promise(function(resolve, reject) {
if (result) {
resolve();
} else {
reject('You need to select something!');
}
});
}
}).then(function(result) {
swal({
type: 'success',
html: 'You selected: ' + result
});
})
<input id="swal2-radio-1" type="radio" name="swal2-radio" value="3">
它应该打印到控制台,这样我就知道它工作了
以下是我目前掌握的代码:
是我做错了什么,还是因为SweetAlert2的工作方式,这不起作用?您必须将事件逐个委托绑定到整个文档中
$(document).on("click",".swal2-container input[name='swal2-radio']", function() {
var id = $('input[name=swal2-radio]:checked').val();
console.log('id: ' + id);
});
检查非常感谢你,我自己永远也不会明白这一点