首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >选择select2后触发操作

选择select2后触发操作
EN

Stack Overflow用户
提问于 2013-09-04 21:24:28
回答 5查看 171.3K关注 0票数 81

我正在使用select2 library进行搜索。

有没有办法在选择搜索结果后触发操作?例如打开弹出窗口或简单的js警报。

代码语言:javascript
复制
$("#e6").select2({
    placeholder: "Enter an item id please",
    minimumInputLength: 1,
    ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
        url: "index.php?r=sia/searchresults",
        dataType: 'jsonp',
        quietMillis: 3000,
        data: function (term, page) {
        return {
            q: term, // search term
            page_limit: 10,
            id: 10
            };
        },
        results: function (data, page) { // parse the results into the format expected by Select2.
            // since we are using custom formatting functions we do not need to alter remote JSON data
            return {results: data};
        },
    },

    formatResult: movieFormatResult, // omitted for brevity, see the source of this page
    formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
    dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
    escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
});
EN

回答 5

Stack Overflow用户

发布于 2017-09-15 22:12:46

它对我来说很有效:

代码语言:javascript
复制
$('#yourselect').on("change", function(e) { 
   // what you would like to happen
});
票数 13
EN

Stack Overflow用户

发布于 2018-09-25 23:42:46

根据我在v.4上的用法,这将会起作用

代码语言:javascript
复制
$('#selectID').on("select2:select", function(e) { 
    //var value = e.params.data;  Using {id,text format}
});

在低于v.4的情况下,这将会起作用:

代码语言:javascript
复制
$('#selectID').on("change", function(e) { 
   //var value = e.params.data; Using {id,text} format
});
票数 8
EN

Stack Overflow用户

发布于 2019-01-08 06:26:11

对于上面的v4

代码语言:javascript
复制
$('#yourselect').on("select2:select", function(e) { 
     // after selection of select2 
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18615108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档