gpt4 book ai didi

jquery - 带有 HTML 和选择的 SweetAlert2

转载 作者:搜寻专家 更新时间:2023-10-31 22:37:59 26 4
gpt4 key购买 nike

我构建了一个包含 HTML 和选择功能的 sweetAlert2 pop。问题是选择框加载在 HTML 下弹出窗口的底部。

            var array = '[{"teachName" : "Pending Account", "teachNum" : "99999999"},{"teachName" : "test, test", "teachNum" : "101-temp"}]';
var options = {};
$.map(array,
function(o){
options[o.teachNum] = o.teachName;
});
swal({
title: date.format("MM/DD/YYYY"),
type: 'info',
input: 'select',
inputOptions: options ,
html: 'Teacher: ' + $("#teacher").val() + '<br /><br /><div style="border:2px solid purple;" >' +
'Hours: ' +
'<input type="text" autofocus id="hours" style="display:block !important;" class="sweet-alert-input"/>' +
'<br />Notes: ' +
'<br /><input type="text" autofocus id="notes" style="display:block !important;" class="sweet-alert-input"/></div>' +
'<button type="' + btn + '" id="btnD" value="' + date.format("MM/DD/YYYY") + '" class="sweet-alert2-button">Save Record</button> ' +
'<button type="' + btn + '" id="btnC" style="background-color: #B9B9B9 !important;" class="sweet-alert2-button">Cancel</button>',

showConfirmButton: false
});

我希望选择框位于 HTML 代码之上。请告诉我如何解决这个问题。这是我的代码。

最佳答案

首先:您的数组定义是错误的:删除字符串定界符。

您可以使用 sweetalert2 onOpen event将您的选择框移动到 HTML 代码上方

为了实现这一点,您可以使用 .insertBefore()

onOpen: function(ele) {
$(ele).find('.swal2-select').insertBefore($(ele).find('.swal2-content div'));
}

片段:

var array = [{"teachName": "Pending Account", "teachNum": "99999999"}, {"teachName": "test, test", "teachNum": "101-temp"}];
var options = {};
$.map(array, function (o) {
options[o.teachNum] = o.teachName;
});
var btn = 'button';
swal({
title: moment().format("MM/DD/YYYY"),
type: 'info',
input: 'select',
inputOptions: options,
html: 'Teacher: ' + $("#teacher").val() + '<br /><br /><div style="border:2px solid purple;" >' +
'Hours: ' +
'<input type="text" autofocus id="hours" style="display:block !important;" class="sweet-alert-input"/>' +
'<br />Notes: ' +
'<br /><input type="text" autofocus id="notes" style="display:block !important;" class="sweet-alert-input"/></div>' +
'<button type="' + btn + '" id="btnD" value="' + moment().format("MM/DD/YYYY") + '" class="sweet-alert2-button">Save Record</button> ' +
'<button type="' + btn + '" id="btnC" style="background-color: #B9B9B9 !important;" class="sweet-alert2-button">Cancel</button>',

showConfirmButton: false,
onOpen: function(ele) {
$(ele).find('.swal2-select').insertBefore($(ele).find('.swal2-content div'));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/sweetalert2/6.5.6/sweetalert2.min.css">
<script src="https://cdn.jsdelivr.net/sweetalert2/6.5.6/sweetalert2.min.js"></script>

关于jquery - 带有 HTML 和选择的 SweetAlert2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43264658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com