JQuery&Rails:输入Enter键后,专注于下一个空输入

时间:2018-07-28 15:49:12

标签: javascript jquery ruby-on-rails

我是JQuery的新手,我想重构我的代码以在输入Enter键之后,专注于下一个空输入。我有以下.html:

<tr>
  <td>...</td>
  <td>
    <input type="text" name="" value="" class="search-product">
  </td>
</tr>

<tr>
  <td>...</td>
  <td>
    <input type="text" name="" value="" class="search-product">
  </td>
</tr>

还有我的.js.erb:

let next_input = $(this).closest('tr').next('tr').find('input:text');
while(next_input.val()) { next_input = next_input.closest('tr').next('tr').find('input:text'); }
next_input.focus();

它就像一种魅力!但是我认为逻辑太多了,我想知道是否可以将其重构为更简单的方式,例如:

$(this).next($("input(:empty)")).focus();

0 个答案:

没有答案