【问题标题】:Align label and select dropdown in the same row in the sweetalert 2 [closed]在 sweetalert 2 的同一行中对齐标签并选择下拉菜单 [关闭]
【发布时间】:2021-01-04 17:16:14
【问题描述】:

我正在寻找可以使用 sweetalert2 在同一行中对齐标签和下拉列表的示例。

我试图添加自定义标签来实现这一点,但它在不同的行中,我想在单击“确定”按钮时控制选定的下拉列表。

下面是我的堆栈闪电战。

https://stackblitz.com/edit/angular-sweetalert-dropdown

【问题讨论】:

    标签: javascript html css angular sweetalert2


    【解决方案1】:

    使用inputLabel + customClass 参数:

    Swal.fire({
      title: 'Select + label in one row',
      input: 'select',
      inputOptions: {
        apples: 'Apples',
        bananas: 'Bananas',
        oranges: 'Oranges'
      },
      inputLabel: 'Select a fruit',
      customClass: {
        input: 'inline-flex',
        inputLabel: 'inline-flex'
      }
    })
    .inline-flex {
      display: inline-flex !important;
      margin: .5em !important;
    }
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> 

    阅读更多关于customClasshttps://sweetalert2.github.io/#customClass

    【讨论】:

      【解决方案2】:

      您可以使用普通/样式的 html 并正常捕获下拉值,如下所示:

       Swal.fire({
      
        showCancelButton: true,
        type: "warning",
        html: ` select reason <select name="cars" id="cars">
                <option value="volvo">Volvo</option>
                <option value="saab">Saab</option>
                <option value="mercedes">Mercedes</option>
                <option value="audi">Audi</option>
                </select>`,
      
        preConfirm: function() {
        var elm = document.getElementById("cars");
        alert(elm.value); // use user selected value freely
        }
      
         });
      

      【讨论】:

      • 但是我会在点击 OK 时取消强制验证,对吗?
      • 按照这个线程github.com/sweetalert2/sweetalert2/issues/247不幸的是,但是你可以自己实现它的逻辑,或者如果你对它没问题的话,覆盖输入字段的默认样式
      猜你喜欢
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多