Arr*_*row 5 html javascript jquery dom
我在tagsinput这个项目中使用我网站上的文本字段.
我正在尝试将焦点设置到文本字段,但它无法正常工作.它给了我以下错误:
Unhandled exception at line 37, column 9 in
LOCALDOMAIN-LINK-REMOVED
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'focus'.
Run Code Online (Sandbox Code Playgroud)
在line (37)这个错误指的是:
searchQueryTB.focus();
Run Code Online (Sandbox Code Playgroud)
我的完整代码是:
document.onload = FocusSearchQueryTextBox();
function FocusSearchQueryTextBox() {
var searchQueryTB = document.getElementsByClassName("TBhandle0F7X");
searchQueryTB.focus();
}
Run Code Online (Sandbox Code Playgroud)
标记:
<input type="text" value="" name="SearchQuery" id="tagsinput" class="TBhandle0F7X" />
Run Code Online (Sandbox Code Playgroud)
所以我假设它可能与文本字段实际上不合适的事实有关textfield,因为它是一个jQuery UI或tagsinput项目使用的东西?或许我错了,但到目前为止我还没有在谷歌上运气,并且在该项目的网站上似乎没有任何与此问题有关的内容.
我也在jQuery中试过这个,但正如预期的那样,它也没有用.同样的错误.
有什么错误或我如何解决这个问题的任何建议?
getElementsByClassName 返回DOM元素的集合,而不是元素本身,即使只有一个元素与类 TBhandle0F7X
你可能想要
var searchQueryTB = document.getElementsByClassName("TBhandle0F7X")[0];
Run Code Online (Sandbox Code Playgroud)