我正在使用select2.js版本:3.4.3和引导
我有一个下拉列表。
当我点击下拉列表时,我得到了包含搜索文本字段的列表。
但我的光标没有集中在搜索文本字段上。
<form:select path="yearAge" id="yearAgeId"
cssClass="form-control search-select static-select">
<form:option value="">Years</form:option>
<c:forEach var="i" begin="1" end="125" >
<form:option value="${i}" label="${i}"></form:option>
</c:forEach>
</form:select>
$(".search-select.static-select").select2({
placeholder: $(this).attr('placeholder'),
allowClear: true
});
单击下拉菜单时,光标焦点应设置为自动搜索文本字段。
谢谢您。。。!!!!!
最佳答案
这个问题可以通过使用setTimeout()函数来延迟focus()的执行时间来解决,我们可以通过在select2.js的3321行修改一个函数来实现。
container.on('open', function () {
self.$search.attr('tabindex', 0);
//self.$search.focus(); remove this line
setTimeout(function () { self.$search.focus(); }, 10);//add this line
});