确定选择输入是否具有焦点

时间:2018-01-04 21:44:42

标签: javascript jquery selectize.js

我通常可以使用path确定特定输入是否具有焦点,但这似乎不适用于选择性输入。

我可以使用$("#my_input").is(":focus")为输入设置焦点,但仍然$("#my_input")[0].selectize.focus()会返回$("#my_input").is(":focus")

当我在Chrome中检查元素时,我可以看到false下方的div具有类属性my_input,但我不清楚如何将其链接到focus

我还尝试了#my_inputdocument.activeElement等,但到目前为止还没有运气

1 个答案:

答案 0 :(得分:1)

Selectize.js隐藏了您在标记中编写的输入,并显示了一些动态元素。

这些是您原始输入的旁边。

尝试:

if( $("#my_input").next(".selectize-control").find(".focus").length>0 ){
  console.log("Selectize is focussed!");
}else{
  console.log("Selectize is NOT focussed.");
}

如果你跟着我这个......通过查看" next" div如果有一个孩子有focus课程,你就会知道它是否专注于......