将焦点设置在下拉切换的角度 js 上的第一个输入字段上

Set focus on the first input field on dropdown toggle through angular js

本文关键字:js 第一个 字段 输入 设置 焦点      更新时间:2023-09-26
<th class="dropdown" id="header">
  <span>Label</span>
    <span id="filter" class="sort_row glyphicon glyphicon-filter   dropdown-toggle" data-toggle="dropdown" ></span>
  <ul class="dropdown-menu filter-dropdown" role="menu">
     <li >
  <span class="input-group value">
<input type="text"  id="inputField1" name="inputField1"  class="form-  control" ng-model='inputFieldFirst'/>
        </span>
       </li>
      </ul>
   </span>
 </th>

在这里,我想在单击过滤器并打开下拉列表时专注于输入字段。有没有办法让我不必使用输入字段的 id 并将焦点设置在下拉列表中存在的输入上

我可能会尝试这个。

$( "#filter" ).click(function() {
  $( ".dropdown-menu input:first-child()" ).focus();
});