jQuery select2。 formatSelection内的输入字段无法获得焦点 [英] jQuery select2. Can't get focus in the input field inside formatSelection
本文介绍了jQuery select2。 formatSelection内的输入字段无法获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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/
推荐答案
您可以尝试以下代码:
You could try the following code:
$(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();
});
});
这篇关于jQuery select2。 formatSelection内的输入字段无法获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文