5

我正在使用带有表单的 SweetAlert2 对话框。我想使用 Bootstrap DateTimePicker 小部件。

日历小部件弹出窗口显示在 SweetAlert 窗口中,而不是在其顶部。这会使警报扩展和收缩 - 您必须在警报内滚动才能查看日历。所需的行为是将日历显示为主页面的子页面并显示在警报的顶部。

https://jsfiddle.net/ghr2bwoc/13/

  swal({
    title: 'Date picker',
    html: '<input id="datepicker">',
    showConfirmButton: false,
    onOpen: function() {
        $('#datepicker').datetimepicker({});
    },

  }).then(function(result) {

  });
4

2 回答 2

11

在样式表中创建一个附加类:

.swal2-overflow {
  overflow-x: visible;
  overflow-y: visible;
}

使用customClass属性将此新类添加到您的甜蜜警报代码中。

swal({
  title: 'Date picker',
  html: '<input id="datepicker">',
  showConfirmButton: false,
  customClass: 'swal2-overflow',
  onOpen: function() {
      $('#datepicker').datetimepicker({});
  },

}).then(function(result) {

});
于 2017-08-25T14:23:25.460 回答
0

如果您和我一样,并且不希望在日期时间选择器出现时自动调整 sweetalert 的高度。max-height: 550px !important;min-height:550px !important;在@taekwondoalex 的答案中添加最大高度和最大宽度 ( )。

所以仍然像这样将自定义类添加到sweetalert;

swal({
  title: 'Date picker',
  html: '<input id="datepicker">',
  showConfirmButton: false,
  customClass: 'custom-swal-class',
  onOpen: function() {
      $('#datepicker').datetimepicker({});
  },

}).then(function(result) {

});

然后添加到您的 css 并更改像素高度以匹配您想要的高度,例如 550px

.custom-swal-class {
    overflow-x: visible;
    overflow-y: visible;
    max-height: 550px !important;
    min-height: 550px !important;
}
于 2017-11-15T05:11:46.667 回答