select2使用

http://www.jb51.net/article/78676.htm


$(document).ready(function () {

    $("#e11").select2({
        placeholder: "Select a client",
        minimumInputLength: 1,
        allowClear: true,
        id: function (results) {
            return {
                id: results.id
            };
        },
        ajax: {
            url: "Tinkerer.aspx/GetClients", // ?searchTerm=" + (term=null)?"":term, // current page's method. GetClients, GetCountries
            quietMillis: 150,
            dataType: 'json',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: function (term, page) {
                return {
                    pageSize: 100,
                    pageNum: page,
                    searchingFor: term
                };
            },
            results: function (data, page) {
                var more = (page * pageSize) < data.Total;
                return {
                    results: data,
                    more: more
                };
            }
        },

        formatResult: ClientFormatResult,
        formatSelection: ClientFormatSelection,
        dropdownCssClass: "bigdrop",
        escapeMarkup: function (m) {
            return m;
        }
    });
})

function ClientFormatResult(clients) {
    var markup = "<table><tr><td>clients.text</td></tr></table>";
    return markup;

}

function ClientFormatSelection(clients) {
    return clients.text; // ClientName
}



jquery select2 如何获取它的value和text
获取value和普通空间获取一样:
<input type="hidden" name="xa" id="xa" data-placeholder=".." style ="width: 360px;"/>
1  $("#xa").val();
2  $("#xa").select2("val");

获取select2的text值:
$("#xa").select2('data').text







阅读更多
个人分类: jquery
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

select2使用

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭