【发布时间】:2017-06-29 21:33:49
【问题描述】:
我有一个带有输入的表单,该表单还嵌入了一个 iFrame,该表单也具有输入(伪 HTML):
<input type="text" name="one" value="one" />
<input type="text" name="two" value="two" />
<input type="text" name="three" value="three" />
<iframe
<input type="text" name="bacon" value="bacon">
</iframe>
<input type="text" name="four" value="four" />
<input type="text" name="five" value="five" />
当用户按下选项卡时,即使在 三个 之后选择 bacon 的 iframe 字段内,它们也会从一个输入到另一个输入。我们都喜欢培根。
我还有一些 javascript 尝试将下一个输入集中在输入键上:
$(document).ready(function() {
$(document).on('keydown', 'input', function(ev) {
// Move to next on enter
if (ev.which === 13) {
var inputs = $(':tabbable');
var next = inputs.index(this) + 1;
var input = inputs.eq(next == inputs.length ? 0 : next);
input.focus();
return false;
}
});
});
问题是 javascript 输入键代码从不关注 bacon 字段,它会直接跳过它。 jsfiddle:
https://jsfiddle.net/54n8mqkh/4/
让我们都跳过包括不使用 iFrame 的答案。我知道这不是一个理想的实现。但是,我会接受任何允许回车键在所有字段中移动的答案,包括使用任何类型的 javascript 的 iframe。它不必是特定于 jquery 的。
我尝试了几种不同的方法来解决这个问题,但我都没有找到有效的方法。提前感谢任何有解决方案的人。
【问题讨论】:
标签: javascript jquery html jquery-ui iframe