jQuery select2。无法在formatSelection内的输入字段中获得焦点

时间:2014-04-13 11:19:56

标签: jquery focus jquery-select2 lostfocus

<select id="e1" multiple="multiple" style="width:300px">
    <option value="AL">Alabama</option>
    <option value="WY">Wyoming</option>
</select>

$("#e1").select2({
    formatSelection:function(state){
        return "<input type=\"text\" value=\""+1+"\" class=\"quantity\"/>" + state.text;
    },
});

示例:http://jsfiddle.net/Gm668/

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

$(document).ready(function() { 

    $("#e1").select2({
        formatSelection:function(state){
           return "<input type=\"text\" value=\""+1+"\" class=\"quantity\"/>" + state.text;
        }
    }).on("select2-focus", function(e) {
        $(".quantity").focus(); 
    });

});