簡體   English   中英

確認select2選擇

[英]Confirm a select2 selection

我正在使用select2 v4,並且當用戶從下拉列表中選擇一個選項時,我試圖顯示一個confirm()

因此,我有事件.on("select2:select", function(e) {}) ,如果用戶從確認對話框中選擇“取消.on("select2:select", function(e) {})我想阻止select2。

我有以下幾點:

    $("#select2users").select2().on("select2:select", function(e) { 
        var data = e.params.data;

        if(!confirm("Are you sure you want to ban this user?")) {
            e.preventDefault();
        }
    })

e.preventDefault(); 在這里似乎沒有任何作用。 我一直在搜索,無法獲得任何體面的答案。 我該怎么辦?

我很傻,我只是通過清除用戶取消的“確認”對話框中的值來實現它。

像這樣:

    $("#select2users").select2().on("select2:select", function(e) { 
        var data = e.params.data;

        if(!confirm("Are you sure you want to ban this user?")) {
            $(this).select2('val', '');
        }
    })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM