select2强制关注页面加载 [英] select2 force focus on page load

查看:113
本文介绍了select2强制关注页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图使select2框在页面加载时以其 focused 状态显示.我尝试了以下方法:

I am trying to make a select2 box appear in its focused state on page load. I have tried the following:

$('#id').select2('focus');
$('#id').trigger('click');
$('#id').trigger('focus');

似乎只有第一行有效,并且确实将select2字段作为焦点,但是它需要额外的按键才能显示搜索字段并允许输入搜索字符串.

Only the first line seems to have any effect, and it does focus the select2 field, however it requires an additional keypress to display the search field, and to allow typing in search string.

因此,如果您加载页面并开始键入:搜索",则"S"将打开搜索框,然后将其余键输入其中,因此您将搜索"earch"

Therefore, if you load the page and start typing: "Search", the "S" will open the search box and then the remainder of the keys will be entered into it, so you'll be searching "earch"

推荐答案

根据Select2文档:

According to the Select2 documentation:

$('#id').select2('open');

应该是您所需要的全部.

Should be all you need.

文档.

这篇关于select2强制关注页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆