jQuery将输入集中在下一个tr->td时,td包含一个输入字段,但从不关注html选择
jQuery focus the input in the next tr -> td when that td contains an input field, but never focus html select
我有以下html:
<tr>
<td>Name</td><td><input type="text" name="a"></td>
</tr>
<tr>
<td>Address</td><td><input type="text" name="b"></td>
</tr>
<tr>
<td>Type</td><td><select name="c"></td>
</tr>
<tr>
<td>Gender</td><td><input type="text" name="d"></td>
</tr>
如果用户在输入"a"中并按下tab键,那么现在焦点转到输入"b",它就可以工作了。但是,一旦用户在输入'b'时进行制表,就不会发生任何事情。我希望jQuery跳过选择字段"c"和焦点输入"d"。
现在我使用它,它工作得很好,但它允许用户将选择标记到焦点。。。相反,我希望它忽略select,并尝试将tr和td中的输入集中在它之后:
$(this).closest('tr').next().find('input:text').first().focus();
您可以在选项卡索引中使用-1将其从订单中删除。
<select tabindex="-1">
为了使用TAB键遍历所有文本输入,解决方案是:
$(function () {
$(':text').on('keydown', function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) { // on tab go to next input
// prevent the default action
e.preventDefault();
// select the next row containing a text input field (skip select!)
// and get the first element
var nextInput = $(e.target).closest('tr').nextAll('tr').filter(function(index, element) {
return $(element).find(':text').length > 0;
}).first().find(':text');
// if next input exists go there, else go to the first one
if (nextInput.length == 0) {
$(':text:first').focus();
} else {
nextInput.focus();
}
}
return false;
});
});
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<table>
<tr>
<td>Name</td>
<td><input type="text" name="a"></td>
</tr>
<tr>
<td>Adress</td>
<td><input type="text" name="b"></td>
</tr>
<tr>
<td>Type</td>
<td><select name="c"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="text" name="d"></td>
</tr>
</table>
相关文章:
- jQuery将输入集中在下一个tr->td时,td包含一个输入字段,但从不关注html选择
- 在td JavaScript中获取隐藏的输入值
- 在 jquery 中的 TR 中查找 td 的所有输入
- jQuery选择器,用于查找包含具有特定值的TD输入的TR
- 在指定的td中查找输入字段的特定值
- 获取不带输入标记的Td-innert html-Jquery
- 根据输入字段中键入的数字更改td单元格的颜色
- 验证输入,更新<td>属性以匹配验证状态
- 获取 td 值并通过 jquery 将其打印在输入文本中
- jQuery 将类附加到输入的父 TD(如果存在 val)
- 带有输入的 td 中的 Jquery 表导航
- 如何通过jQuery将输入文本框更改为表TD
- Jquery 选择在 TD 内的输入
- jQuery从TD(HTML表格)内的输入字段中获取值
- 如何从td中删除显示的值并替换为输入字段
- 找到一个特定的td,并使用jquery将该值分配给文本输入
- 划分<td>通过输入值
- 双击时将输入文本添加到html表td中
- 迭代td内的每个输入字段
- 如何迭代表的td输入/tr